Guest User

Untitled

a guest
Jul 16th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. library(snowfall)
  2.  
  3. bigProcess <- function( x ) {
  4. mean( replicate ( 10^6 , max( rnorm( 100 , x ) ) ) )
  5. }
  6.  
  7. #run the function twice in parallel
  8. start <- Sys.time()
  9. sfInit(cpus=2,type='SOCK',parallel=TRUE)
  10. sfSapply( c(1,5) , bigProcess )
  11. Sys.time() - start
  12.  
  13. #faster than running it twice sequentially
  14. start <- Sys.time()
  15. bigProcess( 1 )
  16. bigProcess( 5 )
  17. Sys.time() - start
Add Comment
Please, Sign In to add comment