colRowLogSumExps - HenrikBengtsson/matrixStats GitHub Wiki

matrixStats: Benchmark report


colLogSumExps() and rowLogSumExps() benchmarks

This report benchmark the performance of colLogSumExps() and rowLogSumExps() against alternative methods.

Alternative methods

  • apply() + matrixStats::logSumExp()
  • apply() + logSumExp0()

where

> logSumExp0 <- function(lx, ...) {
+     iMax <- which.max(lx)
+     log1p(sum(exp(lx[-iMax] - lx[iMax]))) + lx[iMax]
+ }

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 = "double")

Results

10x10 matrix

> X <- data[["10x10"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3125060 166.9    5709258 305.0  5709258 305.0
Vcells 6082171  46.5   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colLogSumExps = colLogSumExps(X, na.rm = FALSE), `apply+logSumExp` = apply(X, 
+     MARGIN = 2L, FUN = logSumExp, na.rm = FALSE), `apply+logSumExp0` = apply(X, MARGIN = 2L, FUN = logSumExp0, 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3123810 166.9    5709258 305.0  5709258 305.0
Vcells 6078811  46.4   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowLogSumExps = rowLogSumExps(X, na.rm = FALSE), `apply+logSumExp` = apply(X, 
+     MARGIN = 1L, FUN = logSumExp, na.rm = FALSE), `apply+logSumExp0` = apply(X, MARGIN = 1L, FUN = logSumExp0, 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colLogSumExps(), apply+logSumExp() and apply+logSumExp0() on 10x10 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colLogSumExps 0.004711 0.0053785 0.0061904 0.0061875 0.0064740 0.022413
2 apply+logSumExp 0.027942 0.0286880 0.0298074 0.0289785 0.0295790 0.093304
3 apply+logSumExp0 0.040223 0.0410755 0.0425898 0.0414120 0.0420965 0.120160
expr min lq mean median uq max
1 colLogSumExps 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 apply+logSumExp 5.931225 5.333829 4.815135 4.683394 4.568891 4.162941
3 apply+logSumExp0 8.538102 7.636981 6.880025 6.692849 6.502394 5.361174

Table: Benchmarking of rowLogSumExps(), apply+logSumExp() and apply+logSumExp0() on 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 rowLogSumExps 0.003931 0.0045605 0.0052921 0.0051975 0.0055465 0.020809
2 apply+logSumExp 0.027059 0.0283460 0.0288380 0.0285820 0.0290240 0.037562
3 apply+logSumExp0 0.039521 0.0403640 0.0422486 0.0408325 0.0416150 0.143933
expr min lq mean median uq max
1 rowLogSumExps 1.00000 1.000000 1.000000 1.000000 1.00000 1.000000
2 apply+logSumExp 6.88349 6.215547 5.449298 5.499182 5.23285 1.805084
3 apply+logSumExp0 10.05368 8.850784 7.983398 7.856181 7.50293 6.916863

Figure: Benchmarking of colLogSumExps(), apply+logSumExp() and apply+logSumExp0() on 10x10 data as well as rowLogSumExps(), apply+logSumExp() and apply+logSumExp0() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colLogSumExps() and rowLogSumExps() on 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 rowLogSumExps 3.931 4.5605 5.29206 5.1975 5.5465 20.809
1 colLogSumExps 4.711 5.3785 6.19036 6.1875 6.4740 22.413
expr min lq mean median uq max
2 rowLogSumExps 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
1 colLogSumExps 1.198423 1.179366 1.169745 1.190476 1.167223 1.077082

Figure: Benchmarking of colLogSumExps() and rowLogSumExps() on 10x10 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

100x100 matrix

> X <- data[["100x100"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3122366 166.8    5709258 305.0  5709258 305.0
Vcells 5695400  43.5   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colLogSumExps = colLogSumExps(X, na.rm = FALSE), `apply+logSumExp` = apply(X, 
+     MARGIN = 2L, FUN = logSumExp, na.rm = FALSE), `apply+logSumExp0` = apply(X, MARGIN = 2L, FUN = logSumExp0, 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3122357 166.8    5709258 305.0  5709258 305.0
Vcells 5705438  43.6   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowLogSumExps = rowLogSumExps(X, na.rm = FALSE), `apply+logSumExp` = apply(X, 
+     MARGIN = 1L, FUN = logSumExp, na.rm = FALSE), `apply+logSumExp0` = apply(X, MARGIN = 1L, FUN = logSumExp0, 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colLogSumExps(), apply+logSumExp() and apply+logSumExp0() on 100x100 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colLogSumExps 0.144814 0.1489935 0.1564726 0.1524205 0.155077 0.317965
2 apply+logSumExp 0.376996 0.3876615 0.4138374 0.3988820 0.407355 0.675291
3 apply+logSumExp0 0.543809 0.5552615 0.5882317 0.5638295 0.584406 0.997865
expr min lq mean median uq max
1 colLogSumExps 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 apply+logSumExp 2.603312 2.601869 2.644791 2.616984 2.626792 2.123790
3 apply+logSumExp0 3.755224 3.726750 3.759327 3.699171 3.768489 3.138286

Table: Benchmarking of rowLogSumExps(), apply+logSumExp() and apply+logSumExp0() on 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 rowLogSumExps 0.142576 0.1465360 0.1538029 0.1486145 0.1516365 0.252212
2 apply+logSumExp 0.337571 0.3462725 0.3577249 0.3517475 0.3596745 0.464570
3 apply+logSumExp0 0.501670 0.5105925 0.5335048 0.5183200 0.5313105 1.012640
expr min lq mean median uq max
1 rowLogSumExps 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 apply+logSumExp 2.367656 2.363054 2.325865 2.366845 2.371952 1.841982
3 apply+logSumExp0 3.518615 3.484417 3.468756 3.487681 3.503843 4.015035

Figure: Benchmarking of colLogSumExps(), apply+logSumExp() and apply+logSumExp0() on 100x100 data as well as rowLogSumExps(), apply+logSumExp() and apply+logSumExp0() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colLogSumExps() and rowLogSumExps() on 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 rowLogSumExps 142.576 146.5360 153.8029 148.6145 151.6365 252.212
1 colLogSumExps 144.814 148.9935 156.4726 152.4205 155.0770 317.965
expr min lq mean median uq max
2 rowLogSumExps 1.000000 1.000000 1.000000 1.00000 1.000000 1.000000
1 colLogSumExps 1.015697 1.016771 1.017358 1.02561 1.022689 1.260705

Figure: Benchmarking of colLogSumExps() and rowLogSumExps() on 100x100 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

1000x10 matrix

> X <- data[["1000x10"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3123119 166.8    5709258 305.0  5709258 305.0
Vcells 5699179  43.5   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colLogSumExps = colLogSumExps(X, na.rm = FALSE), `apply+logSumExp` = apply(X, 
+     MARGIN = 2L, FUN = logSumExp, na.rm = FALSE), `apply+logSumExp0` = apply(X, MARGIN = 2L, FUN = logSumExp0, 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3123110 166.8    5709258 305.0  5709258 305.0
Vcells 5709217  43.6   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowLogSumExps = rowLogSumExps(X, na.rm = FALSE), `apply+logSumExp` = apply(X, 
+     MARGIN = 1L, FUN = logSumExp, na.rm = FALSE), `apply+logSumExp0` = apply(X, MARGIN = 1L, FUN = logSumExp0, 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colLogSumExps(), apply+logSumExp() and apply+logSumExp0() on 1000x10 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colLogSumExps 0.138597 0.1425225 0.1482528 0.1449735 0.1486965 0.227844
2 apply+logSumExp 0.247569 0.2521410 0.2658961 0.2558755 0.2678450 0.421927
3 apply+logSumExp0 0.292441 0.3001360 0.3114358 0.3052375 0.3125925 0.502148
expr min lq mean median uq max
1 colLogSumExps 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 apply+logSumExp 1.786251 1.769131 1.793532 1.764981 1.801287 1.851824
3 apply+logSumExp0 2.110010 2.105885 2.100707 2.105471 2.102218 2.203911

Table: Benchmarking of rowLogSumExps(), apply+logSumExp() and apply+logSumExp0() on 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 rowLogSumExps 0.138389 0.1416500 0.1469657 0.143197 0.1451465 0.244499
2 apply+logSumExp 0.203530 0.2084805 0.2201824 0.210982 0.2151595 0.443498
3 apply+logSumExp0 0.242665 0.2542520 0.2870687 0.262471 0.2723450 0.749272
expr min lq mean median uq max
1 rowLogSumExps 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 apply+logSumExp 1.470709 1.471800 1.498190 1.473369 1.482361 1.813905
3 apply+logSumExp0 1.753499 1.794931 1.953304 1.832936 1.876346 3.064520

Figure: Benchmarking of colLogSumExps(), apply+logSumExp() and apply+logSumExp0() on 1000x10 data as well as rowLogSumExps(), apply+logSumExp() and apply+logSumExp0() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colLogSumExps() and rowLogSumExps() on 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
2 rowLogSumExps 138.389 141.6500 146.9657 143.1970 145.1465 244.499
1 colLogSumExps 138.597 142.5225 148.2528 144.9735 148.6965 227.844
expr min lq mean median uq max
2 rowLogSumExps 1.000000 1.00000 1.000000 1.000000 1.000000 1.0000000
1 colLogSumExps 1.001503 1.00616 1.008758 1.012406 1.024458 0.9318811

Figure: Benchmarking of colLogSumExps() and rowLogSumExps() on 1000x10 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

10x1000 matrix

> X <- data[["10x1000"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3123324 166.9    5709258 305.0  5709258 305.0
Vcells 5699983  43.5   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colLogSumExps = colLogSumExps(X, na.rm = FALSE), `apply+logSumExp` = apply(X, 
+     MARGIN = 2L, FUN = logSumExp, na.rm = FALSE), `apply+logSumExp0` = apply(X, MARGIN = 2L, FUN = logSumExp0, 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3123315 166.9    5709258 305.0  5709258 305.0
Vcells 5710021  43.6   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowLogSumExps = rowLogSumExps(X, na.rm = FALSE), `apply+logSumExp` = apply(X, 
+     MARGIN = 1L, FUN = logSumExp, na.rm = FALSE), `apply+logSumExp0` = apply(X, MARGIN = 1L, FUN = logSumExp0, 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colLogSumExps(), apply+logSumExp() and apply+logSumExp0() on 10x1000 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colLogSumExps 0.174906 0.1833775 0.1889356 0.1866275 0.190627 0.243382
2 apply+logSumExp 1.484172 1.5647530 1.7238867 1.6158270 1.672591 7.587699
3 apply+logSumExp0 2.713384 2.8884045 3.0688846 2.9845470 3.139184 5.327385
expr min lq mean median uq max
1 colLogSumExps 1.000000 1.000000 1.000000 1.000000 1.000000 1.00000
2 apply+logSumExp 8.485541 8.532961 9.124204 8.658033 8.774156 31.17609
3 apply+logSumExp0 15.513384 15.751139 16.243023 15.992000 16.467678 21.88899

Table: Benchmarking of rowLogSumExps(), apply+logSumExp() and apply+logSumExp0() on 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 rowLogSumExps 0.169903 0.182853 0.1947169 0.1904955 0.200595 0.370639
2 apply+logSumExp 1.501635 1.612288 1.7149532 1.6720590 1.765894 2.566579
3 apply+logSumExp0 2.727101 2.940925 3.2458301 3.0681360 3.297706 8.737862
expr min lq mean median uq max
1 rowLogSumExps 1.00000 1.00000 1.000000 1.00000 1.000000 1.000000
2 apply+logSumExp 8.83819 8.81740 8.807419 8.77742 8.803278 6.924741
3 apply+logSumExp0 16.05093 16.08355 16.669485 16.10608 16.439625 23.575128

Figure: Benchmarking of colLogSumExps(), apply+logSumExp() and apply+logSumExp0() on 10x1000 data as well as rowLogSumExps(), apply+logSumExp() and apply+logSumExp0() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colLogSumExps() and rowLogSumExps() on 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 colLogSumExps 174.906 183.3775 188.9356 186.6275 190.627 243.382
2 rowLogSumExps 169.903 182.8530 194.7169 190.4955 200.595 370.639
expr min lq mean median uq max
1 colLogSumExps 1.0000000 1.0000000 1.000000 1.000000 1.000000 1.000000
2 rowLogSumExps 0.9713961 0.9971398 1.030599 1.020726 1.052291 1.522869

Figure: Benchmarking of colLogSumExps() and rowLogSumExps() on 10x1000 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

100x1000 matrix

> X <- data[["100x1000"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3123534 166.9    5709258 305.0  5709258 305.0
Vcells 5700559  43.5   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colLogSumExps = colLogSumExps(X, na.rm = FALSE), `apply+logSumExp` = apply(X, 
+     MARGIN = 2L, FUN = logSumExp, na.rm = FALSE), `apply+logSumExp0` = apply(X, MARGIN = 2L, FUN = logSumExp0, 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3123528 166.9    5709258 305.0  5709258 305.0
Vcells 5800602  44.3   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowLogSumExps = rowLogSumExps(X, na.rm = FALSE), `apply+logSumExp` = apply(X, 
+     MARGIN = 1L, FUN = logSumExp, na.rm = FALSE), `apply+logSumExp0` = apply(X, MARGIN = 1L, FUN = logSumExp0, 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colLogSumExps(), apply+logSumExp() and apply+logSumExp0() on 100x1000 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colLogSumExps 1.417790 1.457731 1.529753 1.492844 1.564750 1.884488
2 apply+logSumExp 3.660052 3.781668 4.276507 3.874757 4.088005 19.181140
3 apply+logSumExp0 5.261778 5.410164 6.188699 5.556923 5.818384 22.539961
expr min lq mean median uq max
1 colLogSumExps 1.000000 1.000000 1.000000 1.000000 1.000000 1.00000
2 apply+logSumExp 2.581519 2.594215 2.795554 2.595554 2.612561 10.17844
3 apply+logSumExp0 3.711253 3.711359 4.045555 3.722373 3.718411 11.96079

Table: Benchmarking of rowLogSumExps(), apply+logSumExp() and apply+logSumExp0() on 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 rowLogSumExps 1.444836 1.506917 1.914530 1.527148 1.739241 16.46213
2 apply+logSumExp 3.265416 3.383584 4.352430 3.604187 4.196493 21.72466
3 apply+logSumExp0 4.871518 4.957777 5.663599 5.143301 6.090921 11.19454
expr min lq mean median uq max
1 rowLogSumExps 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 apply+logSumExp 2.260060 2.245369 2.273368 2.360078 2.412830 1.3196745
3 apply+logSumExp0 3.371675 3.290013 2.958220 3.367914 3.502057 0.6800177

Figure: Benchmarking of colLogSumExps(), apply+logSumExp() and apply+logSumExp0() on 100x1000 data as well as rowLogSumExps(), apply+logSumExp() and apply+logSumExp0() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colLogSumExps() and rowLogSumExps() on 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 colLogSumExps 1.417790 1.457731 1.529753 1.492844 1.564750 1.884488
2 rowLogSumExps 1.444836 1.506917 1.914530 1.527148 1.739241 16.462133
expr min lq mean median uq max
1 colLogSumExps 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000
2 rowLogSumExps 1.019076 1.033742 1.251529 1.022979 1.111514 8.7356

Figure: Benchmarking of colLogSumExps() and rowLogSumExps() on 100x1000 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

1000x100 matrix

> X <- data[["1000x100"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3123749 166.9    5709258 305.0  5709258 305.0
Vcells 5701232  43.5   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colLogSumExps = colLogSumExps(X, na.rm = FALSE), `apply+logSumExp` = apply(X, 
+     MARGIN = 2L, FUN = logSumExp, na.rm = FALSE), `apply+logSumExp0` = apply(X, MARGIN = 2L, FUN = logSumExp0, 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3123740 166.9    5709258 305.0  5709258 305.0
Vcells 5801270  44.3   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowLogSumExps = rowLogSumExps(X, na.rm = FALSE), `apply+logSumExp` = apply(X, 
+     MARGIN = 1L, FUN = logSumExp, na.rm = FALSE), `apply+logSumExp0` = apply(X, MARGIN = 1L, FUN = logSumExp0, 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colLogSumExps(), apply+logSumExp() and apply+logSumExp0() on 1000x100 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colLogSumExps 1.320766 1.373177 1.498353 1.405703 1.574413 2.549168
2 apply+logSumExp 1.903957 1.952604 2.180981 2.000157 2.208100 8.776682
3 apply+logSumExp0 2.333606 2.412297 2.853036 2.470015 2.734105 9.968571
expr min lq mean median uq max
1 colLogSumExps 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 apply+logSumExp 1.441555 1.421961 1.455585 1.422887 1.402491 3.442959
3 apply+logSumExp0 1.766858 1.756727 1.904114 1.757138 1.736586 3.910519

Table: Benchmarking of rowLogSumExps(), apply+logSumExp() and apply+logSumExp0() on 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 rowLogSumExps 1.382286 1.425270 1.465963 1.440092 1.461410 2.368367
2 apply+logSumExp 1.934065 1.972431 4.509755 1.996143 2.060710 232.277247
3 apply+logSumExp0 2.398010 2.444666 2.737051 2.473604 2.625535 9.289263
expr min lq mean median uq max
1 rowLogSumExps 1.000000 1.00000 1.000000 1.000000 1.000000 1.000000
2 apply+logSumExp 1.399179 1.38390 3.076309 1.386122 1.410084 98.074854
3 apply+logSumExp0 1.734815 1.71523 1.867067 1.717671 1.796577 3.922223

Figure: Benchmarking of colLogSumExps(), apply+logSumExp() and apply+logSumExp0() on 1000x100 data as well as rowLogSumExps(), apply+logSumExp() and apply+logSumExp0() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colLogSumExps() and rowLogSumExps() on 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 colLogSumExps 1.320766 1.373177 1.498353 1.405703 1.574413 2.549168
2 rowLogSumExps 1.382286 1.425270 1.465963 1.440092 1.461410 2.368367
expr min lq mean median uq max
1 colLogSumExps 1.000000 1.000000 1.0000000 1.000000 1.0000000 1.0000000
2 rowLogSumExps 1.046579 1.037936 0.9783824 1.024463 0.9282247 0.9290745

Figure: Benchmarking of colLogSumExps() and rowLogSumExps() on 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 16.94 secs.

Reproducibility

To reproduce this report, do:

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

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