Skip to content

Instantly share code, notes, and snippets.

@CnrLwlss
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CnrLwlss/8709261 to your computer and use it in GitHub Desktop.
Save CnrLwlss/8709261 to your computer and use it in GitHub Desktop.
library(parallel)
cores = 5
bigN = 50000000
# Function which can take a noticeable time to run for large N
sumnorm = function(N) sum(rnorm(N))
cl = makeCluster(cores)
parallel = system.time(parLapply(cl,replicate(cores,bigN),sumnorm))
sequential = system.time(lapply(replicate(cores,bigN),sumnorm))
stopCluster(cl)
parallel
sequential
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment