I was wondering how much faster a!=0
is than !a==0
and used the R package microbenchmark.
Here's the code (reduce 3e6 and 100 if your pc is slow):
library("microbenchmark")
a <- sample(0:1, size=3e6, replace=TRUE)
speed <- microbenchmark(a != 0, ! a == 0, times=100)
boxplot(speed, notch=TRUE, unit="ms", log=F)
Everytime, I get a plot like the one below. As expected, the first version is faster (median 26 milliseconds) than the second (33 ms).
But where do these few very high values (outliers) come from? Is that some memory management effect? If I set times to 10, there are no outliers...
Edit: sessionInfo(): R version 3.1.2 (2014-10-31) Platform: x86_64-w64-mingw32/x64 (64-bit)