Skip to content
Prev 365937 / 398502 Next

Benefit of Iterators (package iterator)

Dear Harold,

I get a different story

library(doParallel)
library(microbenchmark)
cl <- makeCluster(4)
registerDoParallel(cl)
x <- matrix(rnorm(1000000), ncol=1000)
itx <- iter(x, by='row')
microbenchmark(
  iterator = foreach(i=itx, .combine=c) %dopar% mean(i),
  base = foreach(i= 1:nrow(x), .combine=c) %dopar% mean(x[i,])
)

Unit: milliseconds
     expr       min         lq       mean     median         uq      max
neval cld
 iterator   2.11206   2.298507   6.254412   2.540116   2.691283  370.623
100  a
     base 390.21825 442.561737 550.169590 452.729684 466.343894 2554.329
100   b

Best regards,


ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to say
what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey

2016-12-08 15:20 GMT+01:00 Doran, Harold <HDoran at air.org>: