-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First attempts to quantify speed of charlatan. Instantiating multiple R6 classes is slow, very visible in fraudster() which initiates all of the providers. Relates to #113
- Loading branch information
1 parent
5ed2ed5
commit 5049f7b
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
library(microbenchmark) | ||
mb_summary <- function(x) { | ||
res <- summary(x, unit="us") | ||
data.frame(name = res$expr, median = res$median) | ||
} | ||
benchmarktime = c(1,10,100,1000,10000) | ||
results<- microbenchmark( | ||
# median | ||
ch_job(n=1), # 761.1 = 761.1 | ||
ch_job(n=10), # 998.2 = 99.82 | ||
ch_job(n=100), # 2748.9 = 27.49 | ||
ch_job(n=1000), # 20558.3 = 20.56 | ||
times = 100L | ||
) | ||
jp<-JobProvider_en_US$new() | ||
|
||
result2=microbenchmark( # median | ||
replicate(1, jp$render()), # 58.08 = 58.08 | ||
replicate(10, jp$render()), # 222.11 = 22.21 | ||
replicate(100, jp$render()), # 1910.45 = 19.10 | ||
replicate(1000, jp$render()), # 19050.15 = 19.05 | ||
times = 100L | ||
) | ||
|
||
result3=microbenchmark( # median | ||
fraudster(locale = "en_US"), # 40771.0 | ||
JobProvider_en_US$new(), # 493.4 | ||
times = 100L | ||
) | ||
|
||
result4 = microbenchmark( | ||
ch_norm(n = 1), # 288.806 | ||
rnorm(1), # 4.544 | ||
ch_norm(n = 100), # 270.063 | ||
rnorm(100), # 7.156 (optimized functions) | ||
times = 100L | ||
) | ||
|
||
# Yes we pay a performance penalty for using R6. | ||
# | ||
# other notes https://r6.r-lib.org/articles/Performance.html | ||
# instantiation speed | ||
# R6$new() 53.05 | ||
# R6 with private fields 75.85 | ||
# | ||
# Instantiating the classes takes a median time of 75.85 ms | ||
# Instantiating JobProvider_en_US$new(), takes 493.4 ms | ||
# | ||
# but instantiating fraudster(locale = "en_US"), takes 40771.0 almost 83 times longer. | ||
# That is a massive class with all sorts of functions. | ||
# | ||
# creating multiple of a thing is always faster. the relative speedup is especially | ||
# noticable after 100 repititions. | ||
# | ||
# This package will never be as fast as the optimized functions like rnorm. (while using it) | ||
# | ||
# maybe add a test for all ch_ functions with 100 reps to be within 30 microseconds? |