Created
November 19, 2016 20:08
-
-
Save kvnkuang/dfb7c441ccb141f7e2aa38c85b53c11b to your computer and use it in GitHub Desktop.
Benchmark the performance of pbapply and 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) | |
timeConsumedPbapply <- data.table() | |
timeConsumedPbmcapply <- data.table() | |
timeConsumedapply <- data.table() | |
numCores <- 4L | |
repeats <- 50 | |
maxNum <- 10 | |
FUN <- sqrt | |
cat("Start benchmarking with pbapply in 5 seconds.\n") | |
Sys.sleep(5) | |
# Check for pbapply | |
for(index in 1:repeats) { | |
time <- system.time(sqrtRes <- pblapply(1:maxNum, FUN, cl = numCores)) | |
timeConsumedPbapply <- rbind(timeConsumedPbapply, as.data.table(t(as.matrix(time)))) | |
} | |
cat("Start benchmarking with pbmcapply in 5 seconds.\n") | |
Sys.sleep(5) | |
# Check for pbmcapply | |
for(index in 1:repeats) { | |
time <- system.time(sqrtRes <- pbmclapply(1:maxNum, FUN, mc.cores = numCores)) | |
timeConsumedPbmcapply <- rbind(timeConsumedPbmcapply, as.data.table(t(as.matrix(time)))) | |
} | |
# Use lapply as reference | |
for(index in 1:repeats) { | |
time <- system.time(sqrtRes <- lapply(1:maxNum, FUN)) | |
timeConsumedapply <- rbind(timeConsumedapply, as.data.table(t(as.matrix(time)))) | |
} | |
cat("\nResutls:\n") | |
colMeans(timeConsumedPbapply) | |
colMeans(timeConsumedPbmcapply) | |
colMeans(timeConsumedapply) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment