Created
November 19, 2016 15:52
-
-
Save kvnkuang/884ac81f5e7d0ff3e262216a230bdc61 to your computer and use it in GitHub Desktop.
R code used for the benchmark of child processes created by pbapply/pbmcapply.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(data.table) | |
library(pbapply) | |
library(pbmcapply) | |
# A lazy sqrt function which doesn't care about efficiency. | |
# It is derived from the testcases of pbmcapply package. | |
# It allows the program to run for a prolonged process so that | |
# we can monitor the forking process. | |
lazySqrt <- function(num) { | |
# Sleep randomly between 0 to 1 second | |
Sys.sleep(runif(1)) | |
return(sqrt(num)) | |
} | |
timeConsumedPbapply <- data.table() | |
timeConsumedPbmcapply <- data.table() | |
numCores <- 4L | |
repeats <- 1 | |
maxNum <- 30 | |
FUN <- lazySqrt | |
cat("Start benchmarking with pbapply in 5 seconds.\n") | |
Sys.sleep(5) | |
# Check for pbapply | |
for(index in 1:repeats) { | |
time <- system.time(sqrt <- pblapply(1:maxNum, FUN, cl = numCores)) | |
} | |
cat("Start benchmarking with pbmcapply in 5 seconds.\n") | |
Sys.sleep(5) | |
# Check for pbmcapply | |
for(index in 1:repeats) { | |
time <- system.time(sqrt <- pbmclapply(1:maxNum, FUN, mc.cores = numCores)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment