Permalink
Browse files

Give df in row study a mix of col types

  • Loading branch information...
jennybc committed Apr 10, 2018
1 parent c8e21c2 commit 52fed9b78629f63cb01dc12ec710a62ee79cc777
Showing with 105 additions and 101 deletions.
  1. +7 −3 iterate-over-rows.R
  2. +98 −98 row-benchmark.csv
  3. BIN row-benchmark.png
@@ -40,7 +40,11 @@ benchmark <- function(n = 1, expr, envir = parent.frame()) {
}

run_row_benchmark <- function(nrow, times = 5) {
df <- data.frame(x = rnorm(nrow), y = runif(nrow), z = runif(nrow))
df <- data.frame(
x = rep_len(letters, length.out = nrow),
y = runif(nrow),
z = seq_len(nrow)
)
res <- list(
transpose = benchmark(times, f_transpose(df)),
pmap = benchmark(times, f_pmap(df)),
@@ -115,14 +119,14 @@ plot_it <- function(df, what = "nrow") {
}

## dry runs
df_test <- run_row_benchmark(nrow = 1000) %>% flevels()
df_test <- run_row_benchmark(nrow = 10000) %>% flevels()
df_test <- run_col_benchmark(ncol = 10000) %>% flevels()
ggplot(df_test, aes(x = method, y = time)) +
geom_jitter(width = 0.25, height = 0) +
scale_y_log10()

## The Real Thing
## fairly fast up to 10^4, go get a coffee at 10^5
## fairly fast up to 10^4, go get a coffee at 10^5 (row case only)
df_r <- map_df(10 ^ (1:5), run_row_benchmark) %>% flevels()
write_csv(df_r, "row-benchmark.csv")

@@ -4,123 +4,123 @@ nrow,method,time
10,transpose,0
10,transpose,0
10,transpose,0
10,pmap,9.999999997489795e-4
10,pmap,0
10,pmap,9.999999999763531e-4
10,pmap,0
10,pmap,0.0010000000002037268
10,pmap,0
10,pmap,9.999999999763531e-4
10,split_lapply,9.999999999763531e-4
10,split_lapply,9.999999999763531e-4
10,split_lapply,0
10,split_lapply,0.0010000000002037268
10,split_lapply,0.0010000000002037268
10,split_lapply,9.999999997489795e-4
10,split_lapply,0.0010000000002037268
10,split_lapply,0
10,lapply_row,9.999999999763531e-4
10,lapply_row,0
10,lapply_row,0
10,lapply_row,9.999999997489795e-4
10,lapply_row,0.0010000000002037268
10,lapply_row,9.999999997489795e-4
10,lapply_row,0
10,lapply_row,0
10,for_loop,0
10,for_loop,9.999999999763531e-4
10,for_loop,0
10,for_loop,0
10,for_loop,9.999999999763531e-4
10,lapply_row,0.0010000000002037268
10,for_loop,0.0010000000002037268
10,for_loop,0.0010000000002037268
10,for_loop,9.999999997489795e-4
10,for_loop,0.0010000000002037268
10,for_loop,9.999999997489795e-4
100,transpose,0
100,transpose,0
100,transpose,0
100,transpose,0
100,transpose,0
100,pmap,9.999999997489795e-4
100,pmap,0
100,pmap,0.0010000000002037268
100,pmap,0
100,pmap,9.999999999763531e-4
100,pmap,0
100,pmap,0
100,split_lapply,0.004000000000132786
100,split_lapply,0.0039999999999054126
100,split_lapply,0.004000000000132786
100,split_lapply,0.004999999999881766
100,split_lapply,0.004000000000132786
100,lapply_row,0.004000000000132786
100,lapply_row,0.0039999999999054126
100,lapply_row,0.0039999999999054126
100,lapply_row,0.003000000000156433
100,lapply_row,0.004999999999881766
100,for_loop,0.0039999999999054126
100,for_loop,0.003000000000156433
100,for_loop,0.0029999999999290594
100,for_loop,0.0029999999999290594
100,for_loop,0.004000000000132786
100,pmap,9.999999997489795e-4
100,split_lapply,0.005999999999858119
100,split_lapply,0.007000000000061846
100,split_lapply,0.007000000000061846
100,split_lapply,0.005999999999858119
100,split_lapply,0.007999999999810825
100,lapply_row,0.007000000000061846
100,lapply_row,0.007000000000061846
100,lapply_row,0.006999999999607098
100,lapply_row,0.007000000000061846
100,lapply_row,0.007000000000061846
100,for_loop,0.008000000000265572
100,for_loop,0.006999999999607098
100,for_loop,0.008000000000265572
100,for_loop,0.007999999999810825
100,for_loop,0.007000000000061846
1e3,transpose,9.999999997489795e-4
1e3,transpose,0
1e3,transpose,0
1e3,transpose,0
1e3,transpose,0
1e3,transpose,0
1e3,pmap,0.0029999999999290594
1e3,pmap,0.0019999999999527063
1e3,pmap,0.0019999999999527063
1e3,pmap,0.00200000000018008
1e3,pmap,0.003000000000156433
1e3,pmap,0.0019999999999527063
1e3,pmap,0.0019999999999527063
1e3,split_lapply,0.04299999999989268
1e3,split_lapply,0.049000000000205546
1e3,split_lapply,0.055999999999812644
1e3,split_lapply,0.04800000000000182
1e3,split_lapply,0.04100000000016735
1e3,lapply_row,0.041999999999916326
1e3,lapply_row,0.04300000000012005
1e3,lapply_row,0.041999999999916326
1e3,lapply_row,0.04800000000000182
1e3,lapply_row,0.03999999999996362
1e3,for_loop,0.038000000000010914
1e3,for_loop,0.04599999999982174
1e3,for_loop,0.0500000000001819
1e3,for_loop,0.03999999999996362
1e3,for_loop,0.03999999999996362
1e4,transpose,9.999999999763531e-4
1e4,transpose,9.999999999763531e-4
1e3,split_lapply,0.0749999999998181
1e3,split_lapply,0.07000000000016371
1e3,split_lapply,0.07699999999977081
1e3,split_lapply,0.07700000000022555
1e3,split_lapply,0.08199999999987995
1e3,lapply_row,0.07099999999991269
1e3,lapply_row,0.07200000000011642
1e3,lapply_row,0.0749999999998181
1e3,lapply_row,0.068000000000211
1e3,lapply_row,0.08399999999983265
1e3,for_loop,0.06599999999980355
1e3,for_loop,0.06500000000005457
1e3,for_loop,0.07100000000036744
1e3,for_loop,0.07699999999977081
1e3,for_loop,0.0729999999998654
1e4,transpose,9.999999997489795e-4
1e4,transpose,0.0019999999999527063
1e4,transpose,9.999999999763531e-4
1e4,transpose,0.0010000000002037268
1e4,transpose,0.0010000000002037268
1e4,transpose,0.0019999999999527063
1e4,pmap,0.020999999999958163
1e4,pmap,0.020999999999958163
1e4,pmap,0.021999999999934516
1e4,pmap,0.0340000000001055
1e4,pmap,0.01999999999998181
1e4,split_lapply,0.7139999999999418
1e4,split_lapply,0.6920000000000073
1e4,split_lapply,0.7250000000001364
1e4,split_lapply,0.8170000000000073
1e4,split_lapply,0.6569999999999254
1e4,lapply_row,0.7139999999999418
1e4,lapply_row,0.724999999999909
1e4,lapply_row,0.8130000000001019
1e4,lapply_row,0.6430000000000291
1e4,lapply_row,0.696999999999889
1e4,for_loop,0.6549999999999727
1e4,for_loop,0.6520000000000437
1e4,for_loop,0.8179999999999836
1e4,for_loop,0.6730000000000018
1e4,for_loop,0.7529999999999291
1e5,transpose,0.01700000000005275
1e5,transpose,0.02599999999983993
1e5,transpose,0.027000000000043656
1e5,transpose,0.027000000000043656
1e5,transpose,0.024000000000114596
1e5,pmap,0.2699999999999818
1e5,pmap,0.4069999999999254
1e5,pmap,0.39200000000005275
1e5,pmap,0.45900000000006
1e5,pmap,0.4410000000000309
1e5,split_lapply,28.932000000000016
1e5,split_lapply,29.593000000000075
1e5,split_lapply,29.945999999999913
1e5,split_lapply,29.642000000000053
1e5,split_lapply,29.83100000000013
1e5,lapply_row,28.102999999999838
1e5,lapply_row,29.287000000000035
1e5,lapply_row,32.519000000000005
1e5,lapply_row,30.47700000000009
1e5,lapply_row,30.90300000000002
1e5,for_loop,29.41800000000012
1e5,for_loop,28.600999999999885
1e5,for_loop,29.138000000000147
1e5,for_loop,26.548999999999978
1e5,for_loop,27.327999999999975
1e4,pmap,0.018999999999778083
1e4,pmap,0.023000000000138243
1e4,pmap,0.02099999999973079
1e4,pmap,0.028999999999996362
1e4,pmap,0.023000000000138243
1e4,split_lapply,1.0340000000001055
1e4,split_lapply,1.074999999999818
1e4,split_lapply,1.0900000000001455
1e4,split_lapply,1.0859999999997854
1e4,split_lapply,1.1520000000000437
1e4,lapply_row,1.0160000000000764
1e4,lapply_row,1.0669999999995525
1e4,lapply_row,1.1410000000000764
1e4,lapply_row,1.2590000000000146
1e4,lapply_row,1.0799999999999272
1e4,for_loop,1.031999999999698
1e4,for_loop,1.0419999999999163
1e4,for_loop,1.1170000000001892
1e4,for_loop,1.1039999999998145
1e4,for_loop,1.0979999999999563
1e5,transpose,0.016999999999825377
1e5,transpose,0.01900000000023283
1e5,transpose,0.021000000000185537
1e5,transpose,0.02099999999973079
1e5,transpose,0.021000000000185537
1e5,pmap,0.23700000000008004
1e5,pmap,0.25700000000006185
1e5,pmap,0.3690000000001419
1e5,pmap,0.29300000000012005
1e5,pmap,0.3819999999996071
1e5,split_lapply,35.738000000000284
1e5,split_lapply,35.86400000000003
1e5,split_lapply,35.68899999999985
1e5,split_lapply,35.559999999999945
1e5,split_lapply,35.922000000000025
1e5,lapply_row,33.54099999999971
1e5,lapply_row,34.87699999999995
1e5,lapply_row,35.669000000000324
1e5,lapply_row,34.465999999999894
1e5,lapply_row,35.59400000000005
1e5,for_loop,35.01800000000003
1e5,for_loop,35.29099999999971
1e5,for_loop,34.46300000000019
1e5,for_loop,35.26099999999997
1e5,for_loop,34.33699999999999
BIN -8.6 KB (96%) row-benchmark.png
Binary file not shown.

0 comments on commit 52fed9b

Please sign in to comment.