colRowSums2 - HenrikBengtsson/matrixStats GitHub Wiki

matrixStats: Benchmark report


colSums2() and rowSums2() benchmarks

This report benchmark the performance of colSums2() and rowSums2() against alternative methods.

Alternative methods

  • apply() + sum()
  • colSums() and rowSums()
  • .colSums() and .rowSums()

Data type "integer"

Data

> rmatrix <- function(nrow, ncol, mode = c("logical", "double", "integer", "index"), range = c(-100, 
+     +100), na_prob = 0) {
+     mode <- match.arg(mode)
+     n <- nrow * ncol
+     if (mode == "logical") {
+         x <- sample(c(FALSE, TRUE), size = n, replace = TRUE)
+     }     else if (mode == "index") {
+         x <- seq_len(n)
+         mode <- "integer"
+     }     else {
+         x <- runif(n, min = range[1], max = range[2])
+     }
+     storage.mode(x) <- mode
+     if (na_prob > 0) 
+         x[sample(n, size = na_prob * n)] <- NA
+     dim(x) <- c(nrow, ncol)
+     x
+ }
> rmatrices <- function(scale = 10, seed = 1, ...) {
+     set.seed(seed)
+     data <- list()
+     data[[1]] <- rmatrix(nrow = scale * 1, ncol = scale * 1, ...)
+     data[[2]] <- rmatrix(nrow = scale * 10, ncol = scale * 10, ...)
+     data[[3]] <- rmatrix(nrow = scale * 100, ncol = scale * 1, ...)
+     data[[4]] <- t(data[[3]])
+     data[[5]] <- rmatrix(nrow = scale * 10, ncol = scale * 100, ...)
+     data[[6]] <- t(data[[5]])
+     names(data) <- sapply(data, FUN = function(x) paste(dim(x), collapse = "x"))
+     data
+ }
> data <- rmatrices(mode = mode)

Results

10x10 integer matrix

> X <- data[["10x10"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3201658 171.0    5709258 305.0  5709258 305.0
Vcells 6523933  49.8   22343563 170.5 56666022 432.4
> colStats <- microbenchmark(colSums2 = colSums2(X, na.rm = FALSE), .colSums = .colSums(X, m = nrow(X), 
+     n = ncol(X), na.rm = FALSE), colSums = colSums(X, na.rm = FALSE), `apply+sum` = apply(X, MARGIN = 2L, 
+     FUN = sum, na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3199978 170.9    5709258 305.0  5709258 305.0
Vcells 6519323  49.8   22343563 170.5 56666022 432.4
> rowStats <- microbenchmark(rowSums2 = rowSums2(X, na.rm = FALSE), .rowSums = .rowSums(X, m = nrow(X), 
+     n = ncol(X), na.rm = FALSE), rowSums = rowSums(X, na.rm = FALSE), `apply+sum` = apply(X, MARGIN = 1L, 
+     FUN = sum, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colSums2(), .colSums(), colSums() and apply+sum() on integer+10x10 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colSums2 0.001133 0.001386 0.0018295 0.0017945 0.0019915 0.012452
2 .colSums 0.001634 0.001849 0.0022563 0.0021175 0.0024265 0.014209
3 colSums 0.002971 0.003299 0.0038329 0.0036710 0.0042280 0.012916
4 apply+sum 0.019245 0.020566 0.0221572 0.0209930 0.0216235 0.113238
expr min lq mean median uq max
1 colSums2 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 .colSums 1.442189 1.334055 1.233285 1.179994 1.218428 1.141102
3 colSums 2.622242 2.380231 2.095098 2.045695 2.123023 1.037263
4 apply+sum 16.985878 14.838384 12.111228 11.698523 10.857896 9.093961

Table: Benchmarking of rowSums2(), .rowSums(), rowSums() and apply+sum() on integer+10x10 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowSums2 0.001095 0.0012995 0.0016709 0.0017025 0.0018095 0.009964
2 .rowSums 0.002430 0.0026155 0.0028790 0.0027960 0.0028985 0.012598
3 rowSums 0.003668 0.0038785 0.0049349 0.0043325 0.0046560 0.036676
4 apply+sum 0.019635 0.0203530 0.0211361 0.0205730 0.0208930 0.063792
expr min lq mean median uq max
1 rowSums2 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 .rowSums 2.219178 2.012697 1.723006 1.642291 1.601824 1.264352
3 rowSums 3.349772 2.984609 2.953468 2.544787 2.573087 3.680851
4 apply+sum 17.931507 15.662178 12.649524 12.083994 11.546283 6.402248

Figure: Benchmarking of colSums2(), .colSums(), colSums() and apply+sum() on integer+10x10 data as well as rowSums2(), .rowSums(), rowSums() and apply+sum() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colSums2() and rowSums2() on integer+10x10 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
2 rowSums2 1.095 1.2995 1.67090 1.7025 1.8095 9.964
1 colSums2 1.133 1.3860 1.82948 1.7945 1.9915 12.452
expr min lq mean median uq max
2 rowSums2 1.000000 1.000000 1.000000 1.000000 1.00000 1.000000
1 colSums2 1.034703 1.066564 1.094907 1.054038 1.10058 1.249699

Figure: Benchmarking of colSums2() and rowSums2() on integer+10x10 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

100x100 integer matrix

> X <- data[["100x100"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3198558 170.9    5709258 305.0  5709258 305.0
Vcells 6136144  46.9   22343563 170.5 56666022 432.4
> colStats <- microbenchmark(colSums2 = colSums2(X, na.rm = FALSE), .colSums = .colSums(X, m = nrow(X), 
+     n = ncol(X), na.rm = FALSE), colSums = colSums(X, na.rm = FALSE), `apply+sum` = apply(X, MARGIN = 2L, 
+     FUN = sum, na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3198549 170.9    5709258 305.0  5709258 305.0
Vcells 6141182  46.9   22343563 170.5 56666022 432.4
> rowStats <- microbenchmark(rowSums2 = rowSums2(X, na.rm = FALSE), .rowSums = .rowSums(X, m = nrow(X), 
+     n = ncol(X), na.rm = FALSE), rowSums = rowSums(X, na.rm = FALSE), `apply+sum` = apply(X, MARGIN = 1L, 
+     FUN = sum, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colSums2(), .colSums(), colSums() and apply+sum() on integer+100x100 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
2 .colSums 0.009088 0.0096250 0.0102482 0.010057 0.010423 0.017808
1 colSums2 0.010865 0.0112420 0.0123764 0.011790 0.012167 0.042313
3 colSums 0.010617 0.0112615 0.0125573 0.011954 0.012511 0.053884
4 apply+sum 0.139616 0.1417465 0.1512812 0.143997 0.149455 0.295777
expr min lq mean median uq max
2 .colSums 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
1 colSums2 1.195533 1.168000 1.207671 1.172318 1.167322 2.376067
3 colSums 1.168244 1.170026 1.225325 1.188625 1.200326 3.025831
4 apply+sum 15.362676 14.726909 14.761794 14.318087 14.338962 16.609221

Table: Benchmarking of rowSums2(), .rowSums(), rowSums() and apply+sum() on integer+100x100 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowSums2 0.011012 0.0113750 0.0118727 0.0117670 0.0121055 0.022659
2 .rowSums 0.038415 0.0386555 0.0390685 0.0389325 0.0391145 0.043933
3 rowSums 0.040014 0.0402805 0.0407892 0.0405575 0.0410045 0.050169
4 apply+sum 0.140327 0.1423640 0.1474834 0.1432280 0.1459140 0.278656
expr min lq mean median uq max
1 rowSums2 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 .rowSums 3.488467 3.398286 3.290620 3.308617 3.231135 1.938876
3 rowSums 3.633672 3.541143 3.435555 3.446715 3.387262 2.214087
4 apply+sum 12.743098 12.515517 12.422081 12.172007 12.053529 12.297807

Figure: Benchmarking of colSums2(), .colSums(), colSums() and apply+sum() on integer+100x100 data as well as rowSums2(), .rowSums(), rowSums() and apply+sum() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colSums2() and rowSums2() on integer+100x100 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
2 rowSums2 11.012 11.375 11.87268 11.767 12.1055 22.659
1 colSums2 10.865 11.242 12.37640 11.790 12.1670 42.313
expr min lq mean median uq max
2 rowSums2 1.0000000 1.0000000 1.000000 1.000000 1.00000 1.000000
1 colSums2 0.9866509 0.9883077 1.042427 1.001955 1.00508 1.867382

Figure: Benchmarking of colSums2() and rowSums2() on integer+100x100 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

1000x10 integer matrix

> X <- data[["1000x10"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3199312 170.9    5709258 305.0  5709258 305.0
Vcells 6139930  46.9   22343563 170.5 56666022 432.4
> colStats <- microbenchmark(colSums2 = colSums2(X, na.rm = FALSE), .colSums = .colSums(X, m = nrow(X), 
+     n = ncol(X), na.rm = FALSE), colSums = colSums(X, na.rm = FALSE), `apply+sum` = apply(X, MARGIN = 2L, 
+     FUN = sum, na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3199303 170.9    5709258 305.0  5709258 305.0
Vcells 6144968  46.9   22343563 170.5 56666022 432.4
> rowStats <- microbenchmark(rowSums2 = rowSums2(X, na.rm = FALSE), .rowSums = .rowSums(X, m = nrow(X), 
+     n = ncol(X), na.rm = FALSE), rowSums = rowSums(X, na.rm = FALSE), `apply+sum` = apply(X, MARGIN = 1L, 
+     FUN = sum, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colSums2(), .colSums(), colSums() and apply+sum() on integer+1000x10 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
2 .colSums 0.009446 0.0097855 0.0101568 0.0100190 0.0104385 0.014322
3 colSums 0.010809 0.0112885 0.0120771 0.0117345 0.0124155 0.025192
1 colSums2 0.012286 0.0126580 0.0131754 0.0130460 0.0134280 0.025906
4 apply+sum 0.068304 0.0723625 0.0743246 0.0731125 0.0739570 0.159002
expr min lq mean median uq max
2 .colSums 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
3 colSums 1.144294 1.153595 1.189057 1.171225 1.189395 1.758972
1 colSums2 1.300656 1.293547 1.297198 1.302126 1.286392 1.808826
4 apply+sum 7.230997 7.394870 7.317678 7.297385 7.085022 11.101941

Table: Benchmarking of rowSums2(), .rowSums(), rowSums() and apply+sum() on integer+1000x10 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowSums2 0.012446 0.0128310 0.0134742 0.0133635 0.0136605 0.028865
4 apply+sum 0.068625 0.0722675 0.0738879 0.0728035 0.0740535 0.134151
2 .rowSums 0.136008 0.1363105 0.1367446 0.1365245 0.1367660 0.141067
3 rowSums 0.137386 0.1379325 0.1391066 0.1384995 0.1387965 0.179794
expr min lq mean median uq max
1 rowSums2 1.00000 1.000000 1.000000 1.000000 1.000000 1.000000
4 apply+sum 5.51382 5.632258 5.483638 5.447936 5.420995 4.647532
2 .rowSums 10.92785 10.623529 10.148591 10.216223 10.011786 4.887130
3 rowSums 11.03857 10.749942 10.323894 10.364014 10.160426 6.228789

Figure: Benchmarking of colSums2(), .colSums(), colSums() and apply+sum() on integer+1000x10 data as well as rowSums2(), .rowSums(), rowSums() and apply+sum() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colSums2() and rowSums2() on integer+1000x10 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colSums2 12.286 12.658 13.17544 13.0460 13.4280 25.906
2 rowSums2 12.446 12.831 13.47424 13.3635 13.6605 28.865
expr min lq mean median uq max
1 colSums2 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowSums2 1.013023 1.013667 1.022679 1.024337 1.017315 1.114221

Figure: Benchmarking of colSums2() and rowSums2() on integer+1000x10 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

10x1000 integer matrix

> X <- data[["10x1000"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3199548 170.9    5709258 305.0  5709258 305.0
Vcells 6140754  46.9   22343563 170.5 56666022 432.4
> colStats <- microbenchmark(colSums2 = colSums2(X, na.rm = FALSE), .colSums = .colSums(X, m = nrow(X), 
+     n = ncol(X), na.rm = FALSE), colSums = colSums(X, na.rm = FALSE), `apply+sum` = apply(X, MARGIN = 2L, 
+     FUN = sum, na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3199539 170.9    5709258 305.0  5709258 305.0
Vcells 6145792  46.9   22343563 170.5 56666022 432.4
> rowStats <- microbenchmark(rowSums2 = rowSums2(X, na.rm = FALSE), .rowSums = .rowSums(X, m = nrow(X), 
+     n = ncol(X), na.rm = FALSE), rowSums = rowSums(X, na.rm = FALSE), `apply+sum` = apply(X, MARGIN = 1L, 
+     FUN = sum, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colSums2(), .colSums(), colSums() and apply+sum() on integer+10x1000 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
2 .colSums 0.008985 0.0094030 0.0100757 0.0097305 0.0102510 0.021481
1 colSums2 0.009497 0.0098950 0.0107956 0.0104910 0.0107835 0.041372
3 colSums 0.010312 0.0111085 0.0120459 0.0118685 0.0126520 0.021115
4 apply+sum 0.790246 0.8194405 0.8353282 0.8273970 0.8535335 0.913296
expr min lq mean median uq max
2 .colSums 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
1 colSums2 1.056984 1.052324 1.071458 1.078156 1.051946 1.9259811
3 colSums 1.147691 1.181378 1.195545 1.219721 1.234221 0.9829617
4 apply+sum 87.951697 87.146709 82.905562 85.031293 83.263438 42.5164564

Table: Benchmarking of rowSums2(), .rowSums(), rowSums() and apply+sum() on integer+10x1000 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowSums2 0.009553 0.0102075 0.0118775 0.0109715 0.0115800 0.020964
2 .rowSums 0.029425 0.0301750 0.0322925 0.0308090 0.0318405 0.050280
3 rowSums 0.031115 0.0321655 0.0361350 0.0331650 0.0347210 0.074309
4 apply+sum 0.787927 0.8261915 0.8764775 0.8407450 0.8615420 1.556184
expr min lq mean median uq max
1 rowSums2 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 .rowSums 3.080184 2.956160 2.718799 2.808094 2.749611 2.398397
3 rowSums 3.257092 3.151163 3.042305 3.022832 2.998359 3.544600
4 apply+sum 82.479535 80.939652 73.793094 76.629905 74.399136 74.231254

Figure: Benchmarking of colSums2(), .colSums(), colSums() and apply+sum() on integer+10x1000 data as well as rowSums2(), .rowSums(), rowSums() and apply+sum() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colSums2() and rowSums2() on integer+10x1000 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colSums2 9.497 9.8950 10.79565 10.4910 10.7835 41.372
2 rowSums2 9.553 10.2075 11.87750 10.9715 11.5800 20.964
expr min lq mean median uq max
1 colSums2 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowSums2 1.005897 1.031582 1.100212 1.045801 1.073863 0.5067195

Figure: Benchmarking of colSums2() and rowSums2() on integer+10x1000 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

100x1000 integer matrix

> X <- data[["100x1000"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3199764 170.9    5709258 305.0  5709258 305.0
Vcells 6141335  46.9   22343563 170.5 56666022 432.4
> colStats <- microbenchmark(colSums2 = colSums2(X, na.rm = FALSE), .colSums = .colSums(X, m = nrow(X), 
+     n = ncol(X), na.rm = FALSE), colSums = colSums(X, na.rm = FALSE), `apply+sum` = apply(X, MARGIN = 2L, 
+     FUN = sum, na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3199758 170.9    5709258 305.0  5709258 305.0
Vcells 6191378  47.3   22343563 170.5 56666022 432.4
> rowStats <- microbenchmark(rowSums2 = rowSums2(X, na.rm = FALSE), .rowSums = .rowSums(X, m = nrow(X), 
+     n = ncol(X), na.rm = FALSE), rowSums = rowSums(X, na.rm = FALSE), `apply+sum` = apply(X, MARGIN = 1L, 
+     FUN = sum, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colSums2(), .colSums(), colSums() and apply+sum() on integer+100x1000 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
2 .colSums 0.075066 0.0760865 0.0774762 0.0773605 0.0783695 0.081952
3 colSums 0.076752 0.0789050 0.0803119 0.0797965 0.0816615 0.095806
1 colSums2 0.097593 0.0996930 0.1011929 0.1005225 0.1022280 0.116382
4 apply+sum 1.260123 1.2886950 1.3070798 1.2987775 1.3199810 1.644839
expr min lq mean median uq max
2 .colSums 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
3 colSums 1.022460 1.037043 1.036601 1.031489 1.042006 1.169050
1 colSums2 1.300096 1.310259 1.306115 1.299403 1.304436 1.420124
4 apply+sum 16.786868 16.937236 16.870718 16.788639 16.843045 20.070761

Table: Benchmarking of rowSums2(), .rowSums(), rowSums() and apply+sum() on integer+100x1000 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowSums2 0.103800 0.1053270 0.1092996 0.1071950 0.1096705 0.148805
2 .rowSums 0.271360 0.2784505 0.2844060 0.2793865 0.2869725 0.333830
3 rowSums 0.273222 0.2805355 0.2893872 0.2838145 0.2966940 0.335396
4 apply+sum 1.268050 1.3040830 1.3567052 1.3238910 1.3614360 1.864570
expr min lq mean median uq max
1 rowSums2 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 .rowSums 2.614258 2.643676 2.602078 2.606339 2.616679 2.243406
3 rowSums 2.632197 2.663472 2.647652 2.647647 2.705322 2.253930
4 apply+sum 12.216281 12.381279 12.412723 12.350305 12.413876 12.530291

Figure: Benchmarking of colSums2(), .colSums(), colSums() and apply+sum() on integer+100x1000 data as well as rowSums2(), .rowSums(), rowSums() and apply+sum() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colSums2() and rowSums2() on integer+100x1000 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colSums2 97.593 99.693 101.1929 100.5225 102.2280 116.382
2 rowSums2 103.800 105.327 109.2996 107.1950 109.6705 148.805
expr min lq mean median uq max
1 colSums2 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowSums2 1.063601 1.056514 1.080111 1.066378 1.072803 1.278591

Figure: Benchmarking of colSums2() and rowSums2() on integer+100x1000 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

1000x100 integer matrix

> X <- data[["1000x100"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3199986 170.9    5709258 305.0  5709258 305.0
Vcells 6142029  46.9   22343563 170.5 56666022 432.4
> colStats <- microbenchmark(colSums2 = colSums2(X, na.rm = FALSE), .colSums = .colSums(X, m = nrow(X), 
+     n = ncol(X), na.rm = FALSE), colSums = colSums(X, na.rm = FALSE), `apply+sum` = apply(X, MARGIN = 2L, 
+     FUN = sum, na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3199980 170.9    5709258 305.0  5709258 305.0
Vcells 6192072  47.3   22343563 170.5 56666022 432.4
> rowStats <- microbenchmark(rowSums2 = rowSums2(X, na.rm = FALSE), .rowSums = .rowSums(X, m = nrow(X), 
+     n = ncol(X), na.rm = FALSE), rowSums = rowSums(X, na.rm = FALSE), `apply+sum` = apply(X, MARGIN = 1L, 
+     FUN = sum, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colSums2(), .colSums(), colSums() and apply+sum() on integer+1000x100 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
2 .colSums 0.079430 0.0798290 0.0813971 0.0801585 0.0809085 0.112326
3 colSums 0.081147 0.0818435 0.0842066 0.0825235 0.0837060 0.156258
1 colSums2 0.104633 0.1050895 0.1062148 0.1054080 0.1060155 0.120491
4 apply+sum 0.543041 0.5528160 0.5673520 0.5599640 0.5732780 0.678743
expr min lq mean median uq max
2 .colSums 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
3 colSums 1.021616 1.025235 1.034516 1.029504 1.034576 1.391112
1 colSums2 1.317298 1.316433 1.304897 1.314995 1.310313 1.072690
4 apply+sum 6.836724 6.925002 6.970173 6.985710 7.085510 6.042617

Table: Benchmarking of rowSums2(), .rowSums(), rowSums() and apply+sum() on integer+1000x100 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowSums2 0.113665 0.115278 0.1194711 0.1168145 0.1192320 0.212273
2 .rowSums 0.371720 0.372579 0.3741557 0.3729915 0.3743710 0.383320
3 rowSums 0.373165 0.374549 0.3768583 0.3751790 0.3763885 0.419846
4 apply+sum 0.565210 0.582445 0.5967722 0.5906430 0.6047140 0.704273
expr min lq mean median uq max
1 rowSums2 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 .rowSums 3.270312 3.232004 3.131767 3.193024 3.139853 1.805788
3 rowSums 3.283025 3.249093 3.154388 3.211750 3.156774 1.977859
4 apply+sum 4.972595 5.052525 4.995116 5.056247 5.071743 3.317770

Figure: Benchmarking of colSums2(), .colSums(), colSums() and apply+sum() on integer+1000x100 data as well as rowSums2(), .rowSums(), rowSums() and apply+sum() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colSums2() and rowSums2() on integer+1000x100 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colSums2 104.633 105.0895 106.2148 105.4080 106.0155 120.491
2 rowSums2 113.665 115.2780 119.4711 116.8145 119.2320 212.273
expr min lq mean median uq max
1 colSums2 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowSums2 1.086321 1.096951 1.124806 1.108213 1.124666 1.761733

Figure: Benchmarking of colSums2() and rowSums2() on integer+1000x100 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

Data type "double"

Data

> rmatrix <- function(nrow, ncol, mode = c("logical", "double", "integer", "index"), range = c(-100, 
+     +100), na_prob = 0) {
+     mode <- match.arg(mode)
+     n <- nrow * ncol
+     if (mode == "logical") {
+         x <- sample(c(FALSE, TRUE), size = n, replace = TRUE)
+     }     else if (mode == "index") {
+         x <- seq_len(n)
+         mode <- "integer"
+     }     else {
+         x <- runif(n, min = range[1], max = range[2])
+     }
+     storage.mode(x) <- mode
+     if (na_prob > 0) 
+         x[sample(n, size = na_prob * n)] <- NA
+     dim(x) <- c(nrow, ncol)
+     x
+ }
> rmatrices <- function(scale = 10, seed = 1, ...) {
+     set.seed(seed)
+     data <- list()
+     data[[1]] <- rmatrix(nrow = scale * 1, ncol = scale * 1, ...)
+     data[[2]] <- rmatrix(nrow = scale * 10, ncol = scale * 10, ...)
+     data[[3]] <- rmatrix(nrow = scale * 100, ncol = scale * 1, ...)
+     data[[4]] <- t(data[[3]])
+     data[[5]] <- rmatrix(nrow = scale * 10, ncol = scale * 100, ...)
+     data[[6]] <- t(data[[5]])
+     names(data) <- sapply(data, FUN = function(x) paste(dim(x), collapse = "x"))
+     data
+ }
> data <- rmatrices(mode = mode)

Results

10x10 double matrix

> X <- data[["10x10"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3200236 171.0    5709258 305.0  5709258 305.0
Vcells 6257960  47.8   22343563 170.5 56666022 432.4
> colStats <- microbenchmark(colSums2 = colSums2(X, na.rm = FALSE), .colSums = .colSums(X, m = nrow(X), 
+     n = ncol(X), na.rm = FALSE), colSums = colSums(X, na.rm = FALSE), `apply+sum` = apply(X, MARGIN = 2L, 
+     FUN = sum, na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3200218 171.0    5709258 305.0  5709258 305.0
Vcells 6258083  47.8   22343563 170.5 56666022 432.4
> rowStats <- microbenchmark(rowSums2 = rowSums2(X, na.rm = FALSE), .rowSums = .rowSums(X, m = nrow(X), 
+     n = ncol(X), na.rm = FALSE), rowSums = rowSums(X, na.rm = FALSE), `apply+sum` = apply(X, MARGIN = 1L, 
+     FUN = sum, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colSums2(), .colSums(), colSums() and apply+sum() on double+10x10 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colSums2 0.001125 0.0014110 0.0018459 0.0018445 0.0019880 0.010989
2 .colSums 0.001679 0.0019315 0.0022807 0.0021570 0.0024595 0.010393
3 colSums 0.002981 0.0033455 0.0039332 0.0037940 0.0043160 0.012126
4 apply+sum 0.020129 0.0214210 0.0226355 0.0217665 0.0222410 0.084903
expr min lq mean median uq max
1 colSums2 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 .colSums 1.492444 1.368887 1.235563 1.169423 1.237173 0.9457639
3 colSums 2.649778 2.371014 2.130780 2.056926 2.171026 1.1034671
4 apply+sum 17.892444 15.181432 12.262471 11.800759 11.187626 7.7261807

Table: Benchmarking of rowSums2(), .rowSums(), rowSums() and apply+sum() on double+10x10 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
2 .rowSums 0.001290 0.0014620 0.0017062 0.0016700 0.0017970 0.007053
1 rowSums2 0.001122 0.0013765 0.0017429 0.0016945 0.0018500 0.011662
3 rowSums 0.002451 0.0028405 0.0036099 0.0032490 0.0034915 0.043073
4 apply+sum 0.019615 0.0205245 0.0215753 0.0208405 0.0213040 0.077098
expr min lq mean median uq max
2 .rowSums 1.0000000 1.0000000 1.000000 1.000000 1.000000 1.000000
1 rowSums2 0.8697674 0.9415185 1.021497 1.014671 1.029494 1.653481
3 rowSums 1.9000000 1.9428865 2.115704 1.945509 1.942961 6.107047
4 apply+sum 15.2054264 14.0386457 12.644882 12.479341 11.855314 10.931235

Figure: Benchmarking of colSums2(), .colSums(), colSums() and apply+sum() on double+10x10 data as well as rowSums2(), .rowSums(), rowSums() and apply+sum() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colSums2() and rowSums2() on double+10x10 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
2 rowSums2 1.122 1.3765 1.74293 1.6945 1.850 11.662
1 colSums2 1.125 1.4110 1.84592 1.8445 1.988 10.989
expr min lq mean median uq max
2 rowSums2 1.000000 1.000000 1.00000 1.000000 1.000000 1.0000000
1 colSums2 1.002674 1.025064 1.05909 1.088522 1.074595 0.9422912

Figure: Benchmarking of colSums2() and rowSums2() on double+10x10 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

100x100 double matrix

> X <- data[["100x100"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3200456 171.0    5709258 305.0  5709258 305.0
Vcells 6258975  47.8   22343563 170.5 56666022 432.4
> colStats <- microbenchmark(colSums2 = colSums2(X, na.rm = FALSE), .colSums = .colSums(X, m = nrow(X), 
+     n = ncol(X), na.rm = FALSE), colSums = colSums(X, na.rm = FALSE), `apply+sum` = apply(X, MARGIN = 2L, 
+     FUN = sum, na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3200447 171.0    5709258 305.0  5709258 305.0
Vcells 6269013  47.9   22343563 170.5 56666022 432.4
> rowStats <- microbenchmark(rowSums2 = rowSums2(X, na.rm = FALSE), .rowSums = .rowSums(X, m = nrow(X), 
+     n = ncol(X), na.rm = FALSE), rowSums = rowSums(X, na.rm = FALSE), `apply+sum` = apply(X, MARGIN = 1L, 
+     FUN = sum, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colSums2(), .colSums(), colSums() and apply+sum() on double+100x100 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
2 .colSums 0.008481 0.0094420 0.0132974 0.0100500 0.0154795 0.086337
1 colSums2 0.011157 0.0122005 0.0158498 0.0129775 0.0166145 0.114645
3 colSums 0.009952 0.0115635 0.0157287 0.0130725 0.0189935 0.045543
4 apply+sum 0.188215 0.2021885 0.2483000 0.2126865 0.2633415 0.930026
expr min lq mean median uq max
2 .colSums 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
1 colSums2 1.315529 1.292152 1.191945 1.291294 1.073323 1.3278780
3 colSums 1.173447 1.224688 1.182834 1.300746 1.227010 0.5275027
4 apply+sum 22.192548 21.413736 18.672754 21.162836 17.012274 10.7720444

Table: Benchmarking of rowSums2(), .rowSums(), rowSums() and apply+sum() on double+100x100 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowSums2 0.011288 0.0117185 0.0124961 0.0121915 0.0125340 0.022394
2 .rowSums 0.019842 0.0202185 0.0215277 0.0203770 0.0206760 0.058601
3 rowSums 0.021223 0.0217120 0.0234411 0.0223080 0.0227835 0.069166
4 apply+sum 0.144447 0.1476880 0.1602648 0.1501135 0.1580005 0.296495
expr min lq mean median uq max
1 rowSums2 1.000000 1.000000 1.000000 1.00000 1.000000 1.000000
2 .rowSums 1.757796 1.725349 1.722759 1.67141 1.649593 2.616817
3 rowSums 1.880138 1.852797 1.875876 1.82980 1.817736 3.088595
4 apply+sum 12.796510 12.602978 12.825207 12.31296 12.605752 13.239930

Figure: Benchmarking of colSums2(), .colSums(), colSums() and apply+sum() on double+100x100 data as well as rowSums2(), .rowSums(), rowSums() and apply+sum() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colSums2() and rowSums2() on double+100x100 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
2 rowSums2 11.288 11.7185 12.49608 12.1915 12.5340 22.394
1 colSums2 11.157 12.2005 15.84983 12.9775 16.6145 114.645
expr min lq mean median uq max
2 rowSums2 1.0000000 1.000000 1.000000 1.000000 1.000000 1.000000
1 colSums2 0.9883948 1.041132 1.268384 1.064471 1.325554 5.119452

Figure: Benchmarking of colSums2() and rowSums2() on double+100x100 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

1000x10 double matrix

> X <- data[["1000x10"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3200682 171.0    5709258 305.0  5709258 305.0
Vcells 6260076  47.8   22343563 170.5 56666022 432.4
> colStats <- microbenchmark(colSums2 = colSums2(X, na.rm = FALSE), .colSums = .colSums(X, m = nrow(X), 
+     n = ncol(X), na.rm = FALSE), colSums = colSums(X, na.rm = FALSE), `apply+sum` = apply(X, MARGIN = 2L, 
+     FUN = sum, na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3200673 171.0    5709258 305.0  5709258 305.0
Vcells 6270114  47.9   22343563 170.5 56666022 432.4
> rowStats <- microbenchmark(rowSums2 = rowSums2(X, na.rm = FALSE), .rowSums = .rowSums(X, m = nrow(X), 
+     n = ncol(X), na.rm = FALSE), rowSums = rowSums(X, na.rm = FALSE), `apply+sum` = apply(X, MARGIN = 1L, 
+     FUN = sum, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colSums2(), .colSums(), colSums() and apply+sum() on double+1000x10 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
2 .colSums 0.009503 0.0098125 0.0105194 0.010159 0.0104955 0.035338
3 colSums 0.010987 0.0114515 0.0123062 0.012100 0.0126045 0.032284
1 colSums2 0.012387 0.0129675 0.0134194 0.013206 0.0134815 0.029126
4 apply+sum 0.116068 0.1181620 0.1211660 0.119921 0.1214535 0.215851
expr min lq mean median uq max
2 .colSums 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
3 colSums 1.156161 1.167032 1.169860 1.191062 1.200943 0.9135775
1 colSums2 1.303483 1.321529 1.275679 1.299931 1.284503 0.8242119
4 apply+sum 12.213827 12.041987 11.518340 11.804410 11.571959 6.1081838

Table: Benchmarking of rowSums2(), .rowSums(), rowSums() and apply+sum() on double+1000x10 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowSums2 0.012830 0.0136550 0.0165813 0.0142095 0.0168490 0.047365
2 .rowSums 0.020297 0.0207485 0.0244345 0.0213450 0.0229405 0.068766
3 rowSums 0.021788 0.0227020 0.0259081 0.0237630 0.0249980 0.068706
4 apply+sum 0.076028 0.0779730 0.1006974 0.0808515 0.0965640 0.340523
expr min lq mean median uq max
1 rowSums2 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 .rowSums 1.581995 1.519480 1.473618 1.502164 1.361535 1.451831
3 rowSums 1.698207 1.662541 1.562492 1.672332 1.483649 1.450565
4 apply+sum 5.925799 5.710216 6.072958 5.689961 5.731141 7.189338

Figure: Benchmarking of colSums2(), .colSums(), colSums() and apply+sum() on double+1000x10 data as well as rowSums2(), .rowSums(), rowSums() and apply+sum() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colSums2() and rowSums2() on double+1000x10 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colSums2 12.387 12.9675 13.41938 13.2060 13.4815 29.126
2 rowSums2 12.830 13.6550 16.58128 14.2095 16.8490 47.365
expr min lq mean median uq max
1 colSums2 1.000000 1.000000 1.000000 1.000000 1.000000 1.00000
2 rowSums2 1.035763 1.053017 1.235622 1.075988 1.249787 1.62621

Figure: Benchmarking of colSums2() and rowSums2() on double+1000x10 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

10x1000 double matrix

> X <- data[["10x1000"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3200903 171.0    5709258 305.0  5709258 305.0
Vcells 6260222  47.8   22343563 170.5 56666022 432.4
> colStats <- microbenchmark(colSums2 = colSums2(X, na.rm = FALSE), .colSums = .colSums(X, m = nrow(X), 
+     n = ncol(X), na.rm = FALSE), colSums = colSums(X, na.rm = FALSE), `apply+sum` = apply(X, MARGIN = 2L, 
+     FUN = sum, na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3200894 171.0    5709258 305.0  5709258 305.0
Vcells 6270260  47.9   22343563 170.5 56666022 432.4
> rowStats <- microbenchmark(rowSums2 = rowSums2(X, na.rm = FALSE), .rowSums = .rowSums(X, m = nrow(X), 
+     n = ncol(X), na.rm = FALSE), rowSums = rowSums(X, na.rm = FALSE), `apply+sum` = apply(X, MARGIN = 1L, 
+     FUN = sum, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colSums2(), .colSums(), colSums() and apply+sum() on double+10x1000 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
2 .colSums 0.009544 0.0101400 0.0112099 0.0104835 0.0111480 0.041096
3 colSums 0.011269 0.0121530 0.0136204 0.0127455 0.0141990 0.029504
1 colSums2 0.012166 0.0131125 0.0141914 0.0136505 0.0143675 0.029272
4 apply+sum 0.795365 0.8482970 0.8751510 0.8732355 0.8967020 1.100357
expr min lq mean median uq max
2 .colSums 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
3 colSums 1.180742 1.198521 1.215033 1.215768 1.273681 0.7179288
1 colSums2 1.274728 1.293146 1.265970 1.302094 1.288796 0.7122834
4 apply+sum 83.336651 83.658481 78.069473 83.296180 80.436132 26.7752823

Table: Benchmarking of rowSums2(), .rowSums(), rowSums() and apply+sum() on double+10x1000 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowSums2 0.012403 0.013533 0.0149897 0.0140480 0.0149865 0.027415
2 .rowSums 0.018839 0.019744 0.0205335 0.0203010 0.0208505 0.027395
3 rowSums 0.019771 0.021400 0.0228646 0.0221615 0.0233765 0.036762
4 apply+sum 0.790190 0.864529 0.8862299 0.8822150 0.9011230 1.170931
expr min lq mean median uq max
1 rowSums2 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 .rowSums 1.518907 1.458952 1.369838 1.445117 1.391285 0.9992705
3 rowSums 1.594050 1.581320 1.525353 1.577556 1.559837 1.3409447
4 apply+sum 63.709586 63.883027 59.122432 62.800043 60.128983 42.7113259

Figure: Benchmarking of colSums2(), .colSums(), colSums() and apply+sum() on double+10x1000 data as well as rowSums2(), .rowSums(), rowSums() and apply+sum() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colSums2() and rowSums2() on double+10x1000 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colSums2 12.166 13.1125 14.19140 13.6505 14.3675 29.272
2 rowSums2 12.403 13.5330 14.98974 14.0480 14.9865 27.415
expr min lq mean median uq max
1 colSums2 1.000000 1.000000 1.000000 1.00000 1.000000 1.0000000
2 rowSums2 1.019481 1.032069 1.056255 1.02912 1.043083 0.9365605

Figure: Benchmarking of colSums2() and rowSums2() on double+10x1000 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

100x1000 double matrix

> X <- data[["100x1000"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3201123 171.0    5709258 305.0  5709258 305.0
Vcells 6261502  47.8   22343563 170.5 56666022 432.4
> colStats <- microbenchmark(colSums2 = colSums2(X, na.rm = FALSE), .colSums = .colSums(X, m = nrow(X), 
+     n = ncol(X), na.rm = FALSE), colSums = colSums(X, na.rm = FALSE), `apply+sum` = apply(X, MARGIN = 2L, 
+     FUN = sum, na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3201117 171.0    5709258 305.0  5709258 305.0
Vcells 6361545  48.6   22343563 170.5 56666022 432.4
> rowStats <- microbenchmark(rowSums2 = rowSums2(X, na.rm = FALSE), .rowSums = .rowSums(X, m = nrow(X), 
+     n = ncol(X), na.rm = FALSE), rowSums = rowSums(X, na.rm = FALSE), `apply+sum` = apply(X, MARGIN = 1L, 
+     FUN = sum, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colSums2(), .colSums(), colSums() and apply+sum() on double+100x1000 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
2 .colSums 0.065601 0.0736915 0.0872300 0.078597 0.0878205 0.173754
3 colSums 0.068018 0.0759150 0.0879334 0.079849 0.0918110 0.157878
1 colSums2 0.099009 0.1106685 0.1192029 0.114086 0.1225600 0.180922
4 apply+sum 1.708269 1.9040275 2.3091431 2.021267 2.1891150 15.793835
expr min lq mean median uq max
2 .colSums 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
3 colSums 1.036844 1.030173 1.008064 1.015929 1.045439 0.9086294
1 colSums2 1.509260 1.501781 1.366536 1.451531 1.395574 1.0412537
4 apply+sum 26.040289 25.837817 26.471895 25.716847 24.927152 90.8976772

Table: Benchmarking of rowSums2(), .rowSums(), rowSums() and apply+sum() on double+100x1000 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowSums2 0.105944 0.1089645 0.1166479 0.1118535 0.1148025 0.232180
2 .rowSums 0.171737 0.1853725 0.1955227 0.1904550 0.1948960 0.276480
3 rowSums 0.179382 0.1836980 0.1924062 0.1909760 0.1927005 0.261175
4 apply+sum 1.309472 1.3688630 1.5825294 1.3847540 1.4315730 15.149573
expr min lq mean median uq max
1 rowSums2 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 .rowSums 1.621017 1.701219 1.676179 1.702718 1.697663 1.190800
3 rowSums 1.693178 1.685852 1.649461 1.707376 1.678539 1.124882
4 apply+sum 12.360039 12.562468 13.566721 12.380069 12.469876 65.249259

Figure: Benchmarking of colSums2(), .colSums(), colSums() and apply+sum() on double+100x1000 data as well as rowSums2(), .rowSums(), rowSums() and apply+sum() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colSums2() and rowSums2() on double+100x1000 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
2 rowSums2 105.944 108.9645 116.6479 111.8535 114.8025 232.180
1 colSums2 99.009 110.6685 119.2029 114.0860 122.5600 180.922
expr min lq mean median uq max
2 rowSums2 1.0000000 1.000000 1.000000 1.000000 1.000000 1.0000000
1 colSums2 0.9345409 1.015638 1.021904 1.019959 1.067573 0.7792316

Figure: Benchmarking of colSums2() and rowSums2() on double+100x1000 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

1000x100 double matrix

> X <- data[["1000x100"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3201358 171.0    5709258 305.0  5709258 305.0
Vcells 6261664  47.8   22343563 170.5 56666022 432.4
> colStats <- microbenchmark(colSums2 = colSums2(X, na.rm = FALSE), .colSums = .colSums(X, m = nrow(X), 
+     n = ncol(X), na.rm = FALSE), colSums = colSums(X, na.rm = FALSE), `apply+sum` = apply(X, MARGIN = 2L, 
+     FUN = sum, na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3201349 171.0    5709258 305.0  5709258 305.0
Vcells 6361702  48.6   22343563 170.5 56666022 432.4
> rowStats <- microbenchmark(rowSums2 = rowSums2(X, na.rm = FALSE), .rowSums = .rowSums(X, m = nrow(X), 
+     n = ncol(X), na.rm = FALSE), rowSums = rowSums(X, na.rm = FALSE), `apply+sum` = apply(X, MARGIN = 1L, 
+     FUN = sum, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colSums2(), .colSums(), colSums() and apply+sum() on double+1000x100 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
2 .colSums 0.077325 0.0781145 0.0829543 0.0792585 0.086708 0.107558
3 colSums 0.079287 0.0801690 0.0853740 0.0817965 0.089144 0.115481
1 colSums2 0.104967 0.1055385 0.1126490 0.1071660 0.120821 0.143122
4 apply+sum 0.591068 0.6022620 0.7025576 0.6200985 0.652509 7.226098
expr min lq mean median uq max
2 .colSums 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
3 colSums 1.025373 1.026301 1.029168 1.032022 1.028094 1.073663
1 colSums2 1.357478 1.351074 1.357964 1.352107 1.393424 1.330650
4 apply+sum 7.643944 7.709990 8.469209 7.823748 7.525361 67.183269

Table: Benchmarking of rowSums2(), .rowSums(), rowSums() and apply+sum() on double+1000x100 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowSums2 0.108654 0.1114860 0.1175326 0.1143585 0.1189145 0.167381
2 .rowSums 0.187866 0.1929845 0.2002140 0.1954265 0.2032060 0.244465
3 rowSums 0.189519 0.1935800 0.2028186 0.1980415 0.2049410 0.279904
4 apply+sum 0.626604 0.6531920 0.7608880 0.6655130 0.7198745 7.481785
expr min lq mean median uq max
1 rowSums2 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 .rowSums 1.729030 1.731020 1.703477 1.708894 1.708841 1.460530
3 rowSums 1.744243 1.736361 1.725638 1.731760 1.723432 1.672257
4 apply+sum 5.766967 5.858960 6.473849 5.819532 6.053715 44.699129

Figure: Benchmarking of colSums2(), .colSums(), colSums() and apply+sum() on double+1000x100 data as well as rowSums2(), .rowSums(), rowSums() and apply+sum() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colSums2() and rowSums2() on double+1000x100 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colSums2 104.967 105.5385 112.6489 107.1660 120.8210 143.122
2 rowSums2 108.654 111.4860 117.5326 114.3585 118.9145 167.381
expr min lq mean median uq max
1 colSums2 1.000000 1.000000 1.000000 1.000000 1.0000000 1.000000
2 rowSums2 1.035125 1.056354 1.043352 1.067116 0.9842205 1.169499

Figure: Benchmarking of colSums2() and rowSums2() on double+1000x100 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

Appendix

Session information

R version 3.6.1 Patched (2019-08-27 r77078)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.3 LTS

Matrix products: default
BLAS:   /home/hb/software/R-devel/R-3-6-branch/lib/R/lib/libRblas.so
LAPACK: /home/hb/software/R-devel/R-3-6-branch/lib/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] microbenchmark_1.4-6    matrixStats_0.55.0-9000 ggplot2_3.2.1          
[4] knitr_1.24              R.devices_2.16.0        R.utils_2.9.0          
[7] R.oo_1.22.0             R.methodsS3_1.7.1       history_0.0.0-9002     

loaded via a namespace (and not attached):
 [1] Biobase_2.45.0       bit64_0.9-7          splines_3.6.1       
 [4] network_1.15         assertthat_0.2.1     highr_0.8           
 [7] stats4_3.6.1         blob_1.2.0           robustbase_0.93-5   
[10] pillar_1.4.2         RSQLite_2.1.2        backports_1.1.4     
[13] lattice_0.20-38      glue_1.3.1           digest_0.6.20       
[16] colorspace_1.4-1     sandwich_2.5-1       Matrix_1.2-17       
[19] XML_3.98-1.20        lpSolve_5.6.13.3     pkgconfig_2.0.2     
[22] genefilter_1.66.0    purrr_0.3.2          ergm_3.10.4         
[25] xtable_1.8-4         mvtnorm_1.0-11       scales_1.0.0        
[28] tibble_2.1.3         annotate_1.62.0      IRanges_2.18.2      
[31] TH.data_1.0-10       withr_2.1.2          BiocGenerics_0.30.0 
[34] lazyeval_0.2.2       mime_0.7             survival_2.44-1.1   
[37] magrittr_1.5         crayon_1.3.4         statnet.common_4.3.0
[40] memoise_1.1.0        laeken_0.5.0         R.cache_0.13.0      
[43] MASS_7.3-51.4        R.rsp_0.43.1         tools_3.6.1         
[46] multcomp_1.4-10      S4Vectors_0.22.1     trust_0.1-7         
[49] munsell_0.5.0        AnnotationDbi_1.46.1 compiler_3.6.1      
[52] rlang_0.4.0          grid_3.6.1           RCurl_1.95-4.12     
[55] cwhmisc_6.6          rappdirs_0.3.1       labeling_0.3        
[58] bitops_1.0-6         base64enc_0.1-3      boot_1.3-23         
[61] gtable_0.3.0         codetools_0.2-16     DBI_1.0.0           
[64] markdown_1.1         R6_2.4.0             zoo_1.8-6           
[67] dplyr_0.8.3          bit_1.1-14           zeallot_0.1.0       
[70] parallel_3.6.1       Rcpp_1.0.2           vctrs_0.2.0         
[73] DEoptimR_1.0-8       tidyselect_0.2.5     xfun_0.9            
[76] coda_0.19-3         

Total processing time was 27.73 secs.

Reproducibility

To reproduce this report, do:

html <- matrixStats:::benchmark('colSums2')

Copyright Henrik Bengtsson. Last updated on 2019-09-10 20:53:36 (-0700 UTC). Powered by RSP.

<script> var link = document.createElement('link'); link.rel = 'icon'; link.href = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAA21BMVEUAAAAAAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8BAf4CAv0DA/wdHeIeHuEfH+AgIN8hId4lJdomJtknJ9g+PsE/P8BAQL9yco10dIt1dYp3d4h4eIeVlWqWlmmXl2iYmGeZmWabm2Tn5xjo6Bfp6Rb39wj4+Af//wA2M9hbAAAASXRSTlMAAQIJCgsMJSYnKD4/QGRlZmhpamtsbautrrCxuru8y8zN5ebn6Pn6+///////////////////////////////////////////LsUNcQAAAS9JREFUOI29k21XgkAQhVcFytdSMqMETU26UVqGmpaiFbL//xc1cAhhwVNf6n5i5z67M2dmYOyfJZUqlVLhkKucG7cgmUZTybDz6g0iDeq51PUr37Ds2cy2/C9NeES5puDjxuUk1xnToZsg8pfA3avHQ3lLIi7iWRrkv/OYtkScxBIMgDee0ALoyxHQBJ68JLCjOtQIMIANF7QG9G9fNnHvisCHBVMKgSJgiz7nE+AoBKrAPA3MgepvgR9TSCasrCKH0eB1wBGBFdCO+nAGjMVGPcQb5bd6mQRegN6+1axOs9nGfYcCtfi4NQosdtH7dB+txFIpXQqN1p9B/asRHToyS0jRgpV7nk4nwcq1BJ+x3Gl/v7S9Wmpp/aGquum7w3ZDyrADFYrl8vHBH+ev9AUASW1dmU4h4wAAAABJRU5ErkJggg==" document.getElementsByTagName('head')[0].appendChild(link); </script>
⚠️ **GitHub.com Fallback** ⚠️