« first day (2175 days earlier)      last day (1000 days later) » 

8:02 AM
@BenBolker An explicit return costs you some nanoseconds.
 
 
7 hours later…
3:05 PM
@Roland No it doesn't:
R> library(microbenchmark)
R> f1 <- function() { 42 }
R> f2 <- function() { return(42) }
R> f3 <- function() { invisible(42) }
R> microbenchmark(f1, f2, f3, times=1e5)
Unit: nanoseconds
 expr min lq    mean median uq  max neval cld
   f1  41 44 45.0876     45 46 3562 1e+05  b
   f2  41 45 46.6959     47 47 7260 1e+05   c
   f3  41 43 43.9254     44 45 3427 1e+05 a
R>
 
 
1 hour later…
4:18 PM
@DirkEddelbuettel whats the "cld" column? My microbenchmark doesn't have that (v 1.4-2.1)
 
I also have 1.4-2.1 and ran the code as shown. Prolly still in the same emacs buffer.
I think it signals how microbenchmark 'chunked' execution.
 
If the ‘multcomp’ package is available a statistical ranking is
calculated and displayed in compact letter display from in the
‘cld’ column.
from ?print.microbenchmark
wow, your computer does nothing a lot quicker than mine..
> microbenchmark(f1,f2,f3,times=1e5)
Unit: nanoseconds
expr min lq mean median uq max neval cld
f1 84 191 312.8651 221 275 76977 1e+05 ab
f2 81 183 307.8006 213 271 58692 1e+05 a
f3 84 202 330.2703 234 291 923697 1e+05 b
>
quad core i7@2.2GHz, R 3.3.1
f1
 
5:08 PM
@DirkEddelbuettel Mmh.
library(microbenchmark)
implicit <- function(x) {sqrt(x)}
explicit <- function(x) {return(sqrt(x))}
microbenchmark(implicit(10), explicit(10), times = 1e5)
Unit: nanoseconds
         expr min  lq     mean median  uq     max neval cld
 implicit(10) 273 294 484.0167    302 394   61565 1e+05  a
 explicit(10) 332 358 582.0769    372 476 1855949 1e+05   b
 
R> f4 <- function(x) { sqrt(x) }
R> f5 <- function(x) { return(sqrt(x)) }
R> f6 <- function(x) { invisible(sqrt(x)) }
R> microbenchmark(f4(2), f5(2), f6(2), times=1e5)
Unit: nanoseconds
  expr min  lq     mean median  uq      max neval cld
 f4(2) 472 532  605.732    567 628    21300 1e+05   a
 f5(2) 584 652  725.158    686 747    30443 1e+05   a
 f6(2) 580 643 1377.670    684 747 59220813 1e+05   a
R>
In another session:
R> f4 <- function(x) { sqrt(x) }
R> f5 <- function(x) { return(sqrt(x)) }
R> f6 <- function(x) { invisible(sqrt(x)) }
R> microbenchmark(f4(2), f5(2), f6(2), times=1e5)
Unit: nanoseconds
  expr min  lq    mean median  uq     max neval cld
 f4(2) 437 468 570.893    500 576   17459 1e+05  a
 f5(2) 533 578 680.912    608 678   22534 1e+05   b
 f6(2) 547 580 726.403    616 698 2936859 1e+05   b
R>
So we are talking
R> (608-500) / 1e5
[1] 0.00108
R>
Worth it?
 
5:27 PM
@DirkEddelbuettel Why divide by 1e5? The timings are already per-call, not total...
The results should be about the same, whether times = 100L or times = 1e9L.
 
Doh. Silly me.
 
Still, 100 nanos in the R world is not going to be the bottleneck for 99.99% of functions.
 
I think there was a BDR quote to that effect but I can't find it in fortunes right now.
 
5:52 PM
Wow. Data Science question answered with suggestion to use ARIMA modelling... on a data set with three points.
 

« first day (2175 days earlier)      last day (1000 days later) »