https://github.com/cran/doParallel
Tip revision: b17d866a871ca8ab0d7e6d03c7f35e05fee010aa authored by Revolution Analytics on 12 April 2012, 00:00:00 UTC
version 1.0.1
version 1.0.1
Tip revision: b17d866
bootParallel.R
library(doParallel)
registerDoParallel()
x <- iris[which(iris[,5] != "setosa"), c(1,5)]
trials <- 10000
ptime <- system.time({
r <- foreach(icount(trials), .combine=cbind) %dopar% {
ind <- sample(100, 100, replace=TRUE)
result1 <- glm(x[ind,2]~x[ind,1], family=binomial(logit))
coefficients(result1)
}
})[3]
cat(sprintf('Parallel time using doParallel on %d workers: %f\n',
getDoParWorkers(), ptime))
stime <- system.time({
r <- foreach(icount(trials), .combine=cbind) %do% {
ind <- sample(100, 100, replace=TRUE)
result1 <- glm(x[ind,2]~x[ind,1], family=binomial(logit))
coefficients(result1)
}
})[3]
cat(sprintf('Sequential time: %f\n', stime))
cat(sprintf('Speed up for %d workers: %f\n',
getDoParWorkers(), round(stime / ptime, digits=2)))