colRowSums2_subset - HenrikBengtsson/matrixStats GitHub Wiki

matrixStats: Benchmark report


colSums2() and rowSums2() benchmarks on subsetted computation

This report benchmark the performance of colSums2() and rowSums2() on subsetted computation.

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"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3197358 170.8    5709258 305.0  5709258 305.0
Vcells 6445683  49.2   22343563 170.5 56666022 432.4
> colStats <- microbenchmark(colSums2_X_S = colSums2(X_S, na.rm = FALSE), `colSums2(X, rows, cols)` = colSums2(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colSums2(X[rows, cols])` = colSums2(X[rows, cols], 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3196131 170.7    5709258 305.0  5709258 305.0
Vcells 6442354  49.2   22343563 170.5 56666022 432.4
> rowStats <- microbenchmark(rowSums2_X_S = rowSums2(X_S, na.rm = FALSE), `rowSums2(X, cols, rows)` = rowSums2(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowSums2(X[cols, rows])` = rowSums2(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colSums2_X_S(), colSums2(X, rows, cols)() and colSums2(X[rows, cols])() 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_X_S 0.001035 0.001066 0.0018599 0.0010845 0.0011400 0.074674
2 colSums2(X, rows, cols) 0.001170 0.001233 0.0012997 0.0012715 0.0013005 0.002546
3 colSums2(X[rows, cols]) 0.001517 0.001661 0.0018492 0.0017720 0.0018835 0.005732
expr min lq mean median uq max
1 colSums2_X_S 1.000000 1.000000 1.0000000 1.000000 1.000000 1.0000000
2 colSums2(X, rows, cols) 1.130435 1.156660 0.6988171 1.172430 1.140789 0.0340949
3 colSums2(X[rows, cols]) 1.465701 1.558161 0.9942578 1.633933 1.652193 0.0767603

Table: Benchmarking of rowSums2_X_S(), rowSums2(X, cols, rows)() and rowSums2(X[cols, rows])() 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_X_S 0.001019 0.0010450 0.0011153 0.0010630 0.0010995 0.003100
2 rowSums2(X, cols, rows) 0.001180 0.0012170 0.0021450 0.0012405 0.0012955 0.087927
3 rowSums2(X[cols, rows]) 0.001502 0.0017075 0.0018608 0.0017550 0.0019160 0.004949
expr min lq mean median uq max
1 rowSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowSums2(X, cols, rows) 1.157998 1.164593 1.923225 1.166980 1.178263 28.363548
3 rowSums2(X[cols, rows]) 1.473994 1.633971 1.668415 1.650988 1.742610 1.596452

Figure: Benchmarking of colSums2_X_S(), colSums2(X, rows, cols)() and colSums2(X[rows, cols])() on integer+10x10 data as well as rowSums2_X_S(), rowSums2(X, cols, rows)() and rowSums2(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colSums2_X_S() and rowSums2_X_S() 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_X_S 1.019 1.045 1.11534 1.0630 1.0995 3.100
1 colSums2_X_S 1.035 1.066 1.85990 1.0845 1.1400 74.674
expr min lq mean median uq max
2 rowSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.00000
1 colSums2_X_S 1.015702 1.020096 1.667563 1.020226 1.036835 24.08839

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

100x100 integer matrix

> X <- data[["100x100"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3194737 170.7    5709258 305.0  5709258 305.0
Vcells 6111235  46.7   22343563 170.5 56666022 432.4
> colStats <- microbenchmark(colSums2_X_S = colSums2(X_S, na.rm = FALSE), `colSums2(X, rows, cols)` = colSums2(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colSums2(X[rows, cols])` = colSums2(X[rows, cols], 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3194728 170.7    5709258 305.0  5709258 305.0
Vcells 6116313  46.7   22343563 170.5 56666022 432.4
> rowStats <- microbenchmark(rowSums2_X_S = rowSums2(X_S, na.rm = FALSE), `rowSums2(X, cols, rows)` = rowSums2(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowSums2(X[cols, rows])` = rowSums2(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colSums2_X_S(), colSums2(X, rows, cols)() and colSums2(X[rows, cols])() 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
1 colSums2_X_S 0.005432 0.0058030 0.0059374 0.0058855 0.0060230 0.008229
2 colSums2(X, rows, cols) 0.006752 0.0072665 0.0074621 0.0074010 0.0075470 0.009545
3 colSums2(X[rows, cols]) 0.013047 0.0134105 0.0139184 0.0135125 0.0136595 0.041372
expr min lq mean median uq max
1 colSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.00000 1.000000
2 colSums2(X, rows, cols) 1.243004 1.252197 1.256805 1.257497 1.25303 1.159922
3 colSums2(X[rows, cols]) 2.401878 2.310960 2.344192 2.295897 2.26789 5.027585

Table: Benchmarking of rowSums2_X_S(), rowSums2(X, cols, rows)() and rowSums2(X[cols, rows])() 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_X_S 0.005461 0.0059245 0.0062030 0.0060805 0.006241 0.011569
2 rowSums2(X, cols, rows) 0.006495 0.0069330 0.0070705 0.0070375 0.007206 0.008143
3 rowSums2(X[cols, rows]) 0.013174 0.0136170 0.0142560 0.0137660 0.013919 0.041166
expr min lq mean median uq max
1 rowSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowSums2(X, cols, rows) 1.189343 1.170225 1.139843 1.157388 1.154623 0.7038638
3 rowSums2(X[cols, rows]) 2.412379 2.298422 2.298229 2.263959 2.230252 3.5583024

Figure: Benchmarking of colSums2_X_S(), colSums2(X, rows, cols)() and colSums2(X[rows, cols])() on integer+100x100 data as well as rowSums2_X_S(), rowSums2(X, cols, rows)() and rowSums2(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colSums2_X_S() and rowSums2_X_S() 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
1 colSums2_X_S 5.432 5.8030 5.93739 5.8855 6.023 8.229
2 rowSums2_X_S 5.461 5.9245 6.20305 6.0805 6.241 11.569
expr min lq mean median uq max
1 colSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowSums2_X_S 1.005339 1.020937 1.044744 1.033132 1.036195 1.405882

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

1000x10 integer matrix

> X <- data[["1000x10"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3195490 170.7    5709258 305.0  5709258 305.0
Vcells 6115306  46.7   22343563 170.5 56666022 432.4
> colStats <- microbenchmark(colSums2_X_S = colSums2(X_S, na.rm = FALSE), `colSums2(X, rows, cols)` = colSums2(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colSums2(X[rows, cols])` = colSums2(X[rows, cols], 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3195481 170.7    5709258 305.0  5709258 305.0
Vcells 6120384  46.7   22343563 170.5 56666022 432.4
> rowStats <- microbenchmark(rowSums2_X_S = rowSums2(X_S, na.rm = FALSE), `rowSums2(X, cols, rows)` = rowSums2(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowSums2(X[cols, rows])` = rowSums2(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colSums2_X_S(), colSums2(X, rows, cols)() and colSums2(X[rows, cols])() 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
1 colSums2_X_S 0.006711 0.0069925 0.0071730 0.0070970 0.0072185 0.009723
2 colSums2(X, rows, cols) 0.007772 0.0079840 0.0083783 0.0080865 0.0082790 0.031142
3 colSums2(X[rows, cols]) 0.014392 0.0146925 0.0150488 0.0148230 0.0150795 0.023435
expr min lq mean median uq max
1 colSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colSums2(X, rows, cols) 1.158099 1.141795 1.168035 1.139425 1.146914 3.202921
3 colSums2(X[rows, cols]) 2.144539 2.101180 2.097980 2.088629 2.089007 2.410264

Table: Benchmarking of rowSums2_X_S(), rowSums2(X, cols, rows)() and rowSums2(X[cols, rows])() 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_X_S 0.006746 0.0070305 0.0075092 0.0071610 0.0073315 0.032304
2 rowSums2(X, cols, rows) 0.007753 0.0080340 0.0082928 0.0081565 0.0082985 0.017996
3 rowSums2(X[cols, rows]) 0.015381 0.0158460 0.0162522 0.0160045 0.0162585 0.025505
expr min lq mean median uq max
1 rowSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowSums2(X, cols, rows) 1.149274 1.142735 1.104351 1.139017 1.131897 0.5570827
3 rowSums2(X[cols, rows]) 2.280018 2.253894 2.164301 2.234953 2.217623 0.7895307

Figure: Benchmarking of colSums2_X_S(), colSums2(X, rows, cols)() and colSums2(X[rows, cols])() on integer+1000x10 data as well as rowSums2_X_S(), rowSums2(X, cols, rows)() and rowSums2(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colSums2_X_S() and rowSums2_X_S() 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_X_S 6.711 6.9925 7.17302 7.097 7.2185 9.723
2 rowSums2_X_S 6.746 7.0305 7.50921 7.161 7.3315 32.304
expr min lq mean median uq max
1 colSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowSums2_X_S 1.005215 1.005434 1.046869 1.009018 1.015654 3.322431

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

10x1000 integer matrix

> X <- data[["10x1000"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3195696 170.7    5709258 305.0  5709258 305.0
Vcells 6116129  46.7   22343563 170.5 56666022 432.4
> colStats <- microbenchmark(colSums2_X_S = colSums2(X_S, na.rm = FALSE), `colSums2(X, rows, cols)` = colSums2(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colSums2(X[rows, cols])` = colSums2(X[rows, cols], 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3195687 170.7    5709258 305.0  5709258 305.0
Vcells 6121207  46.8   22343563 170.5 56666022 432.4
> rowStats <- microbenchmark(rowSums2_X_S = rowSums2(X_S, na.rm = FALSE), `rowSums2(X, cols, rows)` = rowSums2(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowSums2(X[cols, rows])` = rowSums2(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colSums2_X_S(), colSums2(X, rows, cols)() and colSums2(X[rows, cols])() 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
1 colSums2_X_S 0.005439 0.0056395 0.0058294 0.0057710 0.005896 0.007870
2 colSums2(X, rows, cols) 0.007919 0.0081770 0.0087653 0.0083025 0.008490 0.048252
3 colSums2(X[rows, cols]) 0.013958 0.0143835 0.0148283 0.0145720 0.014812 0.025299
expr min lq mean median uq max
1 colSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colSums2(X, rows, cols) 1.455966 1.449951 1.503625 1.438659 1.439959 6.131131
3 colSums2(X[rows, cols]) 2.566281 2.550492 2.543701 2.525039 2.512212 3.214612

Table: Benchmarking of rowSums2_X_S(), rowSums2(X, cols, rows)() and rowSums2(X[cols, rows])() 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_X_S 0.005446 0.0056410 0.0062585 0.0057940 0.0059285 0.042603
2 rowSums2(X, cols, rows) 0.007578 0.0077690 0.0079893 0.0078845 0.0080590 0.010186
3 rowSums2(X[cols, rows]) 0.012853 0.0132495 0.0138788 0.0134000 0.0136290 0.030771
expr min lq mean median uq max
1 rowSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowSums2(X, cols, rows) 1.391480 1.377238 1.276537 1.360804 1.359366 0.2390911
3 rowSums2(X[cols, rows]) 2.360081 2.348786 2.217586 2.312737 2.298895 0.7222731

Figure: Benchmarking of colSums2_X_S(), colSums2(X, rows, cols)() and colSums2(X[rows, cols])() on integer+10x1000 data as well as rowSums2_X_S(), rowSums2(X, cols, rows)() and rowSums2(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colSums2_X_S() and rowSums2_X_S() 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_X_S 5.439 5.6395 5.82942 5.771 5.8960 7.870
2 rowSums2_X_S 5.446 5.6410 6.25854 5.794 5.9285 42.603
expr min lq mean median uq max
1 colSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowSums2_X_S 1.001287 1.000266 1.073613 1.003985 1.005512 5.413342

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

100x1000 integer matrix

> X <- data[["100x1000"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3195895 170.7    5709258 305.0  5709258 305.0
Vcells 6138787  46.9   22343563 170.5 56666022 432.4
> colStats <- microbenchmark(colSums2_X_S = colSums2(X_S, na.rm = FALSE), `colSums2(X, rows, cols)` = colSums2(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colSums2(X[rows, cols])` = colSums2(X[rows, cols], 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3195886 170.7    5709258 305.0  5709258 305.0
Vcells 6188865  47.3   22343563 170.5 56666022 432.4
> rowStats <- microbenchmark(rowSums2_X_S = rowSums2(X_S, na.rm = FALSE), `rowSums2(X, cols, rows)` = rowSums2(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowSums2(X[cols, rows])` = rowSums2(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colSums2_X_S(), colSums2(X, rows, cols)() and colSums2(X[rows, cols])() 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
1 colSums2_X_S 0.044255 0.0445630 0.0448186 0.0447360 0.0449230 0.047774
2 colSums2(X, rows, cols) 0.060130 0.0619820 0.0628707 0.0621915 0.0624515 0.131813
3 colSums2(X[rows, cols]) 0.115757 0.1163415 0.1178107 0.1167395 0.1178850 0.134544
expr min lq mean median uq max
1 colSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colSums2(X, rows, cols) 1.358717 1.390885 1.402781 1.390189 1.390190 2.759095
3 colSums2(X[rows, cols]) 2.615682 2.610720 2.628611 2.609520 2.624157 2.816260

Table: Benchmarking of rowSums2_X_S(), rowSums2(X, cols, rows)() and rowSums2(X[cols, rows])() 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_X_S 0.046350 0.0467460 0.0482821 0.0469635 0.0472640 0.103522
2 rowSums2(X, cols, rows) 0.072971 0.0734845 0.0749694 0.0737825 0.0741945 0.140462
3 rowSums2(X[cols, rows]) 0.109455 0.1105585 0.1134926 0.1113530 0.1130850 0.171994
expr min lq mean median uq max
1 rowSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowSums2(X, cols, rows) 1.574347 1.571996 1.552736 1.571060 1.569789 1.356832
3 rowSums2(X[cols, rows]) 2.361489 2.365090 2.350614 2.371054 2.392624 1.661425

Figure: Benchmarking of colSums2_X_S(), colSums2(X, rows, cols)() and colSums2(X[rows, cols])() on integer+100x1000 data as well as rowSums2_X_S(), rowSums2(X, cols, rows)() and rowSums2(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colSums2_X_S() and rowSums2_X_S() 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_X_S 44.255 44.563 44.81863 44.7360 44.923 47.774
2 rowSums2_X_S 46.350 46.746 48.28211 46.9635 47.264 103.522
expr min lq mean median uq max
1 colSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowSums2_X_S 1.047339 1.048987 1.077278 1.049792 1.052111 2.166911

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

1000x100 integer matrix

> X <- data[["1000x100"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3196111 170.7    5709258 305.0  5709258 305.0
Vcells 6139567  46.9   22343563 170.5 56666022 432.4
> colStats <- microbenchmark(colSums2_X_S = colSums2(X_S, na.rm = FALSE), `colSums2(X, rows, cols)` = colSums2(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colSums2(X[rows, cols])` = colSums2(X[rows, cols], 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3196102 170.7    5709258 305.0  5709258 305.0
Vcells 6189645  47.3   22343563 170.5 56666022 432.4
> rowStats <- microbenchmark(rowSums2_X_S = rowSums2(X_S, na.rm = FALSE), `rowSums2(X, cols, rows)` = rowSums2(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowSums2(X[cols, rows])` = rowSums2(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colSums2_X_S(), colSums2(X, rows, cols)() and colSums2(X[rows, cols])() 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
1 colSums2_X_S 0.052243 0.0525990 0.0529400 0.052829 0.053070 0.057768
2 colSums2(X, rows, cols) 0.056656 0.0572155 0.0575972 0.057503 0.057793 0.061416
3 colSums2(X[rows, cols]) 0.115427 0.1160940 0.1182083 0.116377 0.117003 0.205710
expr min lq mean median uq max
1 colSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colSums2(X, rows, cols) 1.084471 1.087768 1.087970 1.088474 1.088996 1.063149
3 colSums2(X[rows, cols]) 2.209425 2.207152 2.232872 2.202900 2.204692 3.560968

Table: Benchmarking of rowSums2_X_S(), rowSums2(X, cols, rows)() and rowSums2(X[cols, rows])() 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_X_S 0.065064 0.0692190 0.0721003 0.0702745 0.071174 0.115482
2 rowSums2(X, cols, rows) 0.092840 0.0965175 0.1038314 0.0992115 0.099822 0.260106
3 rowSums2(X[cols, rows]) 0.153781 0.1610900 0.1711527 0.1642380 0.172786 0.281755
expr min lq mean median uq max
1 rowSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowSums2(X, cols, rows) 1.426903 1.394379 1.440096 1.411771 1.402507 2.252351
3 rowSums2(X[cols, rows]) 2.363534 2.327251 2.373813 2.337092 2.427656 2.439818

Figure: Benchmarking of colSums2_X_S(), colSums2(X, rows, cols)() and colSums2(X[rows, cols])() on integer+1000x100 data as well as rowSums2_X_S(), rowSums2(X, cols, rows)() and rowSums2(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colSums2_X_S() and rowSums2_X_S() 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_X_S 52.243 52.599 52.94004 52.8290 53.070 57.768
2 rowSums2_X_S 65.064 69.219 72.10032 70.2745 71.174 115.482
expr min lq mean median uq max
1 colSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowSums2_X_S 1.245411 1.315976 1.361924 1.330226 1.341134 1.999065

Figure: Benchmarking of colSums2_X_S() and rowSums2_X_S() 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"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3196329 170.8    5709258 305.0  5709258 305.0
Vcells 6230664  47.6   22343563 170.5 56666022 432.4
> colStats <- microbenchmark(colSums2_X_S = colSums2(X_S, na.rm = FALSE), `colSums2(X, rows, cols)` = colSums2(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colSums2(X[rows, cols])` = colSums2(X[rows, cols], 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3196311 170.8    5709258 305.0  5709258 305.0
Vcells 6230827  47.6   22343563 170.5 56666022 432.4
> rowStats <- microbenchmark(rowSums2_X_S = rowSums2(X_S, na.rm = FALSE), `rowSums2(X, cols, rows)` = rowSums2(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowSums2(X[cols, rows])` = rowSums2(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colSums2_X_S(), colSums2(X, rows, cols)() and colSums2(X[rows, cols])() 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_X_S 0.001048 0.0010800 0.0013177 0.0010990 0.0011815 0.016339
2 colSums2(X, rows, cols) 0.001226 0.0012795 0.0014174 0.0013015 0.0013915 0.005124
3 colSums2(X[rows, cols]) 0.001623 0.0018745 0.0020363 0.0019320 0.0020305 0.007173
expr min lq mean median uq max
1 colSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 colSums2(X, rows, cols) 1.169847 1.184722 1.075631 1.184258 1.177740 0.3136055
3 colSums2(X[rows, cols]) 1.548664 1.735648 1.545343 1.757962 1.718578 0.4390110

Table: Benchmarking of rowSums2_X_S(), rowSums2(X, cols, rows)() and rowSums2(X[cols, rows])() 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
1 rowSums2_X_S 0.001026 0.0010550 0.0011601 0.0010805 0.0012100 0.003327
2 rowSums2(X, cols, rows) 0.001187 0.0012355 0.0015811 0.0012590 0.0013490 0.027926
3 rowSums2(X[cols, rows]) 0.001505 0.0017420 0.0019006 0.0017880 0.0018955 0.006839
expr min lq mean median uq max
1 rowSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowSums2(X, cols, rows) 1.156920 1.171090 1.362856 1.165201 1.114876 8.393748
3 rowSums2(X[cols, rows]) 1.466862 1.651185 1.638222 1.654789 1.566529 2.055606

Figure: Benchmarking of colSums2_X_S(), colSums2(X, rows, cols)() and colSums2(X[rows, cols])() on double+10x10 data as well as rowSums2_X_S(), rowSums2(X, cols, rows)() and rowSums2(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colSums2_X_S() and rowSums2_X_S() 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_X_S 1.026 1.055 1.16013 1.0805 1.2100 3.327
1 colSums2_X_S 1.048 1.080 1.31772 1.0990 1.1815 16.339
expr min lq mean median uq max
2 rowSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.0000000 1.000000
1 colSums2_X_S 1.021443 1.023697 1.135838 1.017122 0.9764463 4.911031

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

100x100 double matrix

> X <- data[["100x100"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3196530 170.8    5709258 305.0  5709258 305.0
Vcells 6236610  47.6   22343563 170.5 56666022 432.4
> colStats <- microbenchmark(colSums2_X_S = colSums2(X_S, na.rm = FALSE), `colSums2(X, rows, cols)` = colSums2(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colSums2(X[rows, cols])` = colSums2(X[rows, cols], 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3196521 170.8    5709258 305.0  5709258 305.0
Vcells 6246688  47.7   22343563 170.5 56666022 432.4
> rowStats <- microbenchmark(rowSums2_X_S = rowSums2(X_S, na.rm = FALSE), `rowSums2(X, cols, rows)` = rowSums2(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowSums2(X[cols, rows])` = rowSums2(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colSums2_X_S(), colSums2(X, rows, cols)() and colSums2(X[rows, cols])() 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
1 colSums2_X_S 0.005751 0.0062130 0.0063442 0.0063030 0.0064105 0.009819
2 colSums2(X, rows, cols) 0.007573 0.0082465 0.0085612 0.0083970 0.0085255 0.023860
3 colSums2(X[rows, cols]) 0.021516 0.0219135 0.0225538 0.0220415 0.0222065 0.054601
expr min lq mean median uq max
1 colSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colSums2(X, rows, cols) 1.316814 1.327298 1.349457 1.332223 1.329927 2.429983
3 colSums2(X[rows, cols]) 3.741262 3.527040 3.555020 3.496986 3.464082 5.560750

Table: Benchmarking of rowSums2_X_S(), rowSums2(X, cols, rows)() and rowSums2(X[cols, rows])() 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_X_S 0.005822 0.0063485 0.0066357 0.0065035 0.0066975 0.013942
2 rowSums2(X, cols, rows) 0.007646 0.0080775 0.0082670 0.0082705 0.0083845 0.010039
3 rowSums2(X[cols, rows]) 0.013164 0.0137735 0.0144908 0.0140090 0.0142765 0.056080
expr min lq mean median uq max
1 rowSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowSums2(X, cols, rows) 1.313294 1.272348 1.245838 1.271700 1.251885 0.7200545
3 rowSums2(X[cols, rows]) 2.261079 2.169568 2.183781 2.154071 2.131616 4.0223784

Figure: Benchmarking of colSums2_X_S(), colSums2(X, rows, cols)() and colSums2(X[rows, cols])() on double+100x100 data as well as rowSums2_X_S(), rowSums2(X, cols, rows)() and rowSums2(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colSums2_X_S() and rowSums2_X_S() 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
1 colSums2_X_S 5.751 6.2130 6.34421 6.3030 6.4105 9.819
2 rowSums2_X_S 5.822 6.3485 6.63566 6.5035 6.6975 13.942
expr min lq mean median uq max
1 colSums2_X_S 1.000000 1.000000 1.00000 1.00000 1.00000 1.0000
2 rowSums2_X_S 1.012346 1.021809 1.04594 1.03181 1.04477 1.4199

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

1000x10 double matrix

> X <- data[["1000x10"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3196740 170.8    5709258 305.0  5709258 305.0
Vcells 6238016  47.6   22343563 170.5 56666022 432.4
> colStats <- microbenchmark(colSums2_X_S = colSums2(X_S, na.rm = FALSE), `colSums2(X, rows, cols)` = colSums2(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colSums2(X[rows, cols])` = colSums2(X[rows, cols], 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3196731 170.8    5709258 305.0  5709258 305.0
Vcells 6248094  47.7   22343563 170.5 56666022 432.4
> rowStats <- microbenchmark(rowSums2_X_S = rowSums2(X_S, na.rm = FALSE), `rowSums2(X, cols, rows)` = rowSums2(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowSums2(X[cols, rows])` = rowSums2(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colSums2_X_S(), colSums2(X, rows, cols)() and colSums2(X[rows, cols])() 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
1 colSums2_X_S 0.006733 0.0070935 0.0073250 0.0072105 0.0073500 0.010209
2 colSums2(X, rows, cols) 0.007890 0.0082095 0.0087692 0.0084055 0.0085800 0.043921
3 colSums2(X[rows, cols]) 0.022668 0.0228990 0.0231386 0.0230505 0.0231465 0.029557
expr min lq mean median uq max
1 colSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colSums2(X, rows, cols) 1.171840 1.157327 1.197152 1.165731 1.167347 4.302184
3 colSums2(X[rows, cols]) 3.366701 3.228167 3.158856 3.196796 3.149184 2.895191

Table: Benchmarking of rowSums2_X_S(), rowSums2(X, cols, rows)() and rowSums2(X[cols, rows])() 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_X_S 0.006847 0.007174 0.0075666 0.0072990 0.0074375 0.024413
2 rowSums2(X, cols, rows) 0.008029 0.008363 0.0087446 0.0085465 0.0087715 0.022805
3 rowSums2(X[cols, rows]) 0.015980 0.016389 0.0168253 0.0166000 0.0168715 0.029119
expr min lq mean median uq max
1 rowSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowSums2(X, cols, rows) 1.172630 1.165737 1.155671 1.170914 1.179361 0.9341335
3 rowSums2(X[cols, rows]) 2.333869 2.284500 2.223621 2.274284 2.268437 1.1927661

Figure: Benchmarking of colSums2_X_S(), colSums2(X, rows, cols)() and colSums2(X[rows, cols])() on double+1000x10 data as well as rowSums2_X_S(), rowSums2(X, cols, rows)() and rowSums2(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colSums2_X_S() and rowSums2_X_S() 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_X_S 6.733 7.0935 7.32501 7.2105 7.3500 10.209
2 rowSums2_X_S 6.847 7.1740 7.56664 7.2990 7.4375 24.413
expr min lq mean median uq max
1 colSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowSums2_X_S 1.016932 1.011348 1.032987 1.012274 1.011905 2.391321

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

10x1000 double matrix

> X <- data[["10x1000"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3196946 170.8    5709258 305.0  5709258 305.0
Vcells 6238153  47.6   22343563 170.5 56666022 432.4
> colStats <- microbenchmark(colSums2_X_S = colSums2(X_S, na.rm = FALSE), `colSums2(X, rows, cols)` = colSums2(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colSums2(X[rows, cols])` = colSums2(X[rows, cols], 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3196937 170.8    5709258 305.0  5709258 305.0
Vcells 6248231  47.7   22343563 170.5 56666022 432.4
> rowStats <- microbenchmark(rowSums2_X_S = rowSums2(X_S, na.rm = FALSE), `rowSums2(X, cols, rows)` = rowSums2(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowSums2(X[cols, rows])` = rowSums2(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colSums2_X_S(), colSums2(X, rows, cols)() and colSums2(X[rows, cols])() 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
1 colSums2_X_S 0.007668 0.0079515 0.0081400 0.0080375 0.0081905 0.013034
2 colSums2(X, rows, cols) 0.009935 0.0102115 0.0108178 0.0104055 0.0105705 0.046167
3 colSums2(X[rows, cols]) 0.016587 0.0170885 0.0173450 0.0172285 0.0174825 0.023320
expr min lq mean median uq max
1 colSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colSums2(X, rows, cols) 1.295644 1.284223 1.328963 1.294619 1.290581 3.542044
3 colSums2(X[rows, cols]) 2.163146 2.149091 2.130834 2.143515 2.134485 1.789167

Table: Benchmarking of rowSums2_X_S(), rowSums2(X, cols, rows)() and rowSums2(X[cols, rows])() 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_X_S 0.007668 0.0079165 0.0082255 0.0079875 0.0081200 0.024201
2 rowSums2(X, cols, rows) 0.009576 0.0098405 0.0100772 0.0099830 0.0101225 0.014620
3 rowSums2(X[cols, rows]) 0.015401 0.0157295 0.0162166 0.0159225 0.0161545 0.031760
expr min lq mean median uq max
1 rowSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowSums2(X, cols, rows) 1.248826 1.243037 1.225110 1.249828 1.246613 0.6041073
3 rowSums2(X[cols, rows]) 2.008477 1.986926 1.971497 1.993427 1.989470 1.3123425

Figure: Benchmarking of colSums2_X_S(), colSums2(X, rows, cols)() and colSums2(X[rows, cols])() on double+10x1000 data as well as rowSums2_X_S(), rowSums2(X, cols, rows)() and rowSums2(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colSums2_X_S() and rowSums2_X_S() 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
2 rowSums2_X_S 7.668 7.9165 8.22553 7.9875 8.1200 24.201
1 colSums2_X_S 7.668 7.9515 8.14000 8.0375 8.1905 13.034
expr min lq mean median uq max
2 rowSums2_X_S 1 1.000000 1.0000000 1.00000 1.000000 1.0000000
1 colSums2_X_S 1 1.004421 0.9896019 1.00626 1.008682 0.5385728

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

100x1000 double matrix

> X <- data[["100x1000"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3197145 170.8    5709258 305.0  5709258 305.0
Vcells 6283589  48.0   22343563 170.5 56666022 432.4
> colStats <- microbenchmark(colSums2_X_S = colSums2(X_S, na.rm = FALSE), `colSums2(X, rows, cols)` = colSums2(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colSums2(X[rows, cols])` = colSums2(X[rows, cols], 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3197136 170.8    5709258 305.0  5709258 305.0
Vcells 6383667  48.8   22343563 170.5 56666022 432.4
> rowStats <- microbenchmark(rowSums2_X_S = rowSums2(X_S, na.rm = FALSE), `rowSums2(X, cols, rows)` = rowSums2(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowSums2(X[cols, rows])` = rowSums2(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colSums2_X_S(), colSums2(X, rows, cols)() and colSums2(X[rows, cols])() 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
1 colSums2_X_S 0.047286 0.047713 0.0533056 0.0480610 0.0491315 0.098006
2 colSums2(X, rows, cols) 0.068441 0.068929 0.0806109 0.0691405 0.0700825 0.166081
3 colSums2(X[rows, cols]) 0.194958 0.196620 0.2215189 0.1983200 0.2033505 0.398980
expr min lq mean median uq max
1 colSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colSums2(X, rows, cols) 1.447384 1.444659 1.512241 1.438599 1.426427 1.694600
3 colSums2(X[rows, cols]) 4.122954 4.120889 4.155640 4.126423 4.138903 4.070975

Table: Benchmarking of rowSums2_X_S(), rowSums2(X, cols, rows)() and rowSums2(X[cols, rows])() 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_X_S 0.054898 0.0599035 0.0642159 0.0632010 0.0658030 0.175677
2 rowSums2(X, cols, rows) 0.098190 0.1074955 0.1120233 0.1146325 0.1156095 0.172798
3 rowSums2(X[cols, rows]) 0.134321 0.1497480 0.1604563 0.1582800 0.1666785 0.283316
expr min lq mean median uq max
1 rowSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowSums2(X, cols, rows) 1.788590 1.794478 1.744479 1.813777 1.756903 0.983612
3 rowSums2(X[cols, rows]) 2.446738 2.499820 2.498700 2.504391 2.532992 1.612710

Figure: Benchmarking of colSums2_X_S(), colSums2(X, rows, cols)() and colSums2(X[rows, cols])() on double+100x1000 data as well as rowSums2_X_S(), rowSums2(X, cols, rows)() and rowSums2(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colSums2_X_S() and rowSums2_X_S() 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
1 colSums2_X_S 47.286 47.7130 53.30559 48.061 49.1315 98.006
2 rowSums2_X_S 54.898 59.9035 64.21591 63.201 65.8030 175.677
expr min lq mean median uq max
1 colSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowSums2_X_S 1.160978 1.255496 1.204675 1.315016 1.339324 1.792513

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

1000x100 double matrix

> X <- data[["1000x100"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3197361 170.8    5709258 305.0  5709258 305.0
Vcells 6283736  48.0   22343563 170.5 56666022 432.4
> colStats <- microbenchmark(colSums2_X_S = colSums2(X_S, na.rm = FALSE), `colSums2(X, rows, cols)` = colSums2(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colSums2(X[rows, cols])` = colSums2(X[rows, cols], 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3197352 170.8    5709258 305.0  5709258 305.0
Vcells 6383814  48.8   22343563 170.5 56666022 432.4
> rowStats <- microbenchmark(rowSums2_X_S = rowSums2(X_S, na.rm = FALSE), `rowSums2(X, cols, rows)` = rowSums2(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowSums2(X[cols, rows])` = rowSums2(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colSums2_X_S(), colSums2(X, rows, cols)() and colSums2(X[rows, cols])() 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
1 colSums2_X_S 0.065700 0.0679140 0.0717249 0.0688030 0.070108 0.224654
2 colSums2(X, rows, cols) 0.076613 0.0775345 0.0824399 0.0797165 0.080192 0.179692
3 colSums2(X[rows, cols]) 0.151623 0.1551100 0.1647623 0.1575745 0.159926 0.473810
expr min lq mean median uq max
1 colSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 colSums2(X, rows, cols) 1.166103 1.141657 1.149390 1.158619 1.143835 0.7998611
3 colSums2(X[rows, cols]) 2.307808 2.283918 2.297142 2.290227 2.281138 2.1090655

Table: Benchmarking of rowSums2_X_S(), rowSums2(X, cols, rows)() and rowSums2(X[cols, rows])() 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_X_S 0.053853 0.0543835 0.0553172 0.054743 0.0551475 0.095029
2 rowSums2(X, cols, rows) 0.090008 0.0904435 0.0908911 0.090631 0.0909460 0.096691
3 rowSums2(X[cols, rows]) 0.130907 0.1357240 0.1411041 0.139254 0.1423040 0.299043
expr min lq mean median uq max
1 rowSums2_X_S 1.000000 1.000000 1.00000 1.000000 1.000000 1.000000
2 rowSums2(X, cols, rows) 1.671365 1.663069 1.64309 1.655572 1.649141 1.017489
3 rowSums2(X[cols, rows]) 2.430821 2.495683 2.55082 2.543777 2.580425 3.146860

Figure: Benchmarking of colSums2_X_S(), colSums2(X, rows, cols)() and colSums2(X[rows, cols])() on double+1000x100 data as well as rowSums2_X_S(), rowSums2(X, cols, rows)() and rowSums2(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colSums2_X_S() and rowSums2_X_S() 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
2 rowSums2_X_S 53.853 54.3835 55.31715 54.743 55.1475 95.029
1 colSums2_X_S 65.700 67.9140 71.72489 68.803 70.1080 224.654
expr min lq mean median uq max
2 rowSums2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
1 colSums2_X_S 1.219988 1.248798 1.296612 1.256836 1.271282 2.364057

Figure: Benchmarking of colSums2_X_S() and rowSums2_X_S() 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 23.4 secs.

Reproducibility

To reproduce this report, do:

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

Copyright Henrik Bengtsson. Last updated on 2019-09-10 20:53:07 (-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** ⚠️