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 Sailingmake, 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.
As the other answer stated, it seems that the Windows timer does not have enough precision to measure execution time, i.e. execution time is < 1 nanosecond. If we make a simple change to the source of the package in the
nanotimer.c
file to thedo_microtiming()
C function...And then test it out...
It seems that you can't measure sub nanosecond times on yours (and mine) Windows system with current drivers.
So execution time is not negative, it's just so small you cannot measure it.