I am getting to know some of the microbenchmark
R
package's featrues. I implemented a sample code from this publication of Hadley Wickham and received an error I cannot find any precise information about and I cannot deal with. Thank you in advance for any explanation / hint etc.
An example code:
library(microbenchmark)
f <- function() NULL
microbenchmark(
NULL,
f()
)
Console output:
Error in microbenchmark(NULL, f()) :
Measured negative execution time! Please investigate and/or contact the package author.
UPDATE. Here is my seesionInfo()
console output:
> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=Polish_Poland.1250 LC_CTYPE=Polish_Poland.1250 LC_MONETARY=Polish_Poland.1250
[4] LC_NUMERIC=C LC_TIME=Polish_Poland.1250
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggplot2_0.9.3.1 microbenchmark_1.3-0
loaded via a namespace (and not attached):
[1] colorspace_1.2-4 dichromat_2.0-0 digest_0.6.3 grid_3.0.2 gtable_0.1.2 labeling_0.2
[7] MASS_7.3-29 munsell_0.4.2 plyr_1.8 proto_0.3-10 RColorBrewer_1.0-5 reshape2_1.2.2
[13] scales_0.2.3 stringr_0.6.2 tools_3.0.2
UPDATE 2. Some further information the author of the package asked me for:
R variable R.version
R.version _
platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 3
minor 0.2
year 2013
month 09
day 25
svn rev 63987
language R
version.string R version 3.0.2 (2013-09-25) nickname Frisbee Sailing
make, model and speed of the CPU in my computer:
Processor: Intel(R) Core(TM) i7-2600K CPU @ 3.40GHz 3.70 GHz
RAM: 16,0 GB
System type: 64-bits
UPDATE 3.
I have noticed that one of the modifications of the code above does return a correct result:
> ### 1
> f <- function(){NULL}
> microbenchmark(NULL, f())
Error in microbenchmark(NULL, f()) :
Measured negative execution time! Please investigate and/or contact the package author.
>
>
> ### 2
> f <- function(){ }
> microbenchmark(NULL, f())
Error in microbenchmark(NULL, f()) :
Measured negative execution time! Please investigate and/or contact the package author.
>
>
> ### 3
> f <- function(){NULL}
> microbenchmark(f())
Unit: nanoseconds
expr min lq median uq max neval
f() 0 1 1 1 7245 100
>
> ### 4
> f <- function(){ }
> microbenchmark(f())
Error in microbenchmark(f()) :
Measured negative execution time! Please investigate and/or contact the package author.
Common sources of error include instrumental, environmental, procedural, and human. All of these errors can be either random or systematic depending on how they affect the results. Instrumental error happens when the instruments being used are inaccurate, such as a balance that does not work (SF Fig. 1.4).
While you can't eradicate it completely, you can reduce random error by taking repeated measurements, using a large sample, and controlling extraneous variables. You can avoid systematic error through careful design of your sampling, data collection, and analysis procedures.
Measurement uncertainty is critical to risk assessment and decision making. Organizations make decisions every day based on reports containing quantitative measurement data. If measurement results are not accurate, then decision risks increase. Selecting the wrong suppliers, could result in poor product quality.
Depending on what operating system you're using, there may be a problem with the installed drivers for the High Performance Timer subsystem on your computer.
In Windows land, one accesses the HPT through the QueryPerformanceCounter
and QueryPerformanceFrequency
functions. QPF tells you how frequently the counter ticks and thus tells you the accuracy of the counter; QPC / QPF gives you a value in seconds, usually of how long the computer has been booted.
The problem is that driver support for this API is sometimes spotty. AMD particularly has had trouble in the past, I've personally experienced this.
You can try searching online for drivers for your CPU and/or motherboard to see if you're missing drivers. That may fix this.
Edit:
@MatthewLundberg is on point about the rdtsc instruction on different cores sometimes being slightly off. One cheap way to get around this is to change the cpu affinity for the program so that it only runs on one core.
Assuming you're on Win Vista or later, go into Task Manager, right click the process that is running your code, select 'Affinity...' and restrict it to only one processor (the first CPU is fine).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With