colRowDiffs - HenrikBengtsson/matrixStats GitHub Wiki

matrixStats: Benchmark report


colDiffs() and rowDiffs() benchmarks

This report benchmark the performance of colDiffs() and rowDiffs() against alternative methods.

Alternative methods

  • apply() + diff()
  • apply() + diff2()
  • diff()

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 3118071 166.6    5709258 305.0  5709258 305.0
Vcells 5912815  45.2   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colDiffs = colDiffs(X), `apply+diff` = apply(X, MARGIN = 2L, FUN = diff), 
+     `apply+diff2` = apply(X, MARGIN = 2L, FUN = diff2), diff = diff(X), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3116682 166.5    5709258 305.0  5709258 305.0
Vcells 5909095  45.1   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowDiffs = rowDiffs(X), `apply+diff` = apply(X, MARGIN = 1L, FUN = diff), 
+     `apply+diff2` = apply(X, MARGIN = 1L, FUN = diff2), `diff + t` = diff(t(X)), unit = "ms")

Table: Benchmarking of colDiffs(), apply+diff(), apply+diff2() and diff() 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 colDiffs 0.001270 0.0018170 0.0021640 0.0020725 0.0022715 0.011992
4 diff 0.006379 0.0071075 0.0086773 0.0082010 0.0086415 0.069156
3 apply+diff2 0.033844 0.0344875 0.0359664 0.0348345 0.0353310 0.119466
2 apply+diff 0.067467 0.0683645 0.0703230 0.0691400 0.0697245 0.128498
expr min lq mean median uq max
1 colDiffs 1.000000 1.000000 1.00000 1.000000 1.000000 1.000000
4 diff 5.022835 3.911668 4.00976 3.957057 3.804314 5.766845
3 apply+diff2 26.648819 18.980462 16.62004 16.807961 15.554039 9.962141
2 apply+diff 53.123622 37.624931 32.49617 33.360675 30.695356 10.715310

Table: Benchmarking of rowDiffs(), apply+diff(), apply+diff2() and diff + t() 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 rowDiffs 0.001278 0.0017735 0.0020819 0.0020560 0.002277 0.007329
4 diff + t 0.009225 0.0100965 0.0115328 0.0115210 0.012146 0.029634
3 apply+diff2 0.033501 0.0343785 0.0363943 0.0349085 0.035424 0.139590
2 apply+diff 0.067405 0.0688215 0.0701873 0.0694390 0.070156 0.093201
expr min lq mean median uq max
1 rowDiffs 1.00000 1.00000 1.000000 1.000000 1.000000 1.000000
4 diff + t 7.21831 5.69298 5.539625 5.603599 5.334212 4.043389
3 apply+diff2 26.21362 19.38455 17.481548 16.978842 15.557312 19.046255
2 apply+diff 52.74257 38.80547 33.713604 33.773833 30.810716 12.716742

Figure: Benchmarking of colDiffs(), apply+diff(), apply+diff2() and diff() on integer+10x10 data as well as rowDiffs(), apply+diff(), apply+diff2() and diff + t() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colDiffs() and rowDiffs() 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 rowDiffs 1.278 1.7735 2.08187 2.0560 2.2770 7.329
1 colDiffs 1.270 1.8170 2.16404 2.0725 2.2715 11.992
expr min lq mean median uq max
2 rowDiffs 1.0000000 1.000000 1.000000 1.000000 1.0000000 1.00000
1 colDiffs 0.9937402 1.024528 1.039469 1.008025 0.9975845 1.63624

Figure: Benchmarking of colDiffs() and rowDiffs() 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 3115258 166.4    5709258 305.0  5709258 305.0
Vcells 5525911  42.2   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colDiffs = colDiffs(X), `apply+diff` = apply(X, MARGIN = 2L, FUN = diff), 
+     `apply+diff2` = apply(X, MARGIN = 2L, FUN = diff2), diff = diff(X), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3115249 166.4    5709258 305.0  5709258 305.0
Vcells 5530949  42.2   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowDiffs = rowDiffs(X), `apply+diff` = apply(X, MARGIN = 1L, FUN = diff), 
+     `apply+diff2` = apply(X, MARGIN = 1L, FUN = diff2), `diff + t` = diff(t(X)), unit = "ms")

Table: Benchmarking of colDiffs(), apply+diff(), apply+diff2() and diff() 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 colDiffs 0.009920 0.0109060 0.0119752 0.0114910 0.0118260 0.040385
4 diff 0.080247 0.0821780 0.0854313 0.0834555 0.0842980 0.137403
3 apply+diff2 0.241004 0.2459205 0.2529544 0.2478870 0.2517745 0.418276
2 apply+diff 0.675984 0.6930305 0.7169101 0.7018950 0.7154390 1.138782
expr min lq mean median uq max
1 colDiffs 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
4 diff 8.089415 7.535118 7.134028 7.262684 7.128192 3.402328
3 apply+diff2 24.294758 22.549101 21.123206 21.572274 21.289912 10.357212
2 apply+diff 68.143548 63.545800 59.866280 61.082151 60.497125 28.198143

Table: Benchmarking of rowDiffs(), apply+diff(), apply+diff2() and diff + t() 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 rowDiffs 0.009978 0.0108210 0.0112527 0.0111070 0.0114755 0.019667
4 diff + t 0.095520 0.0974725 0.0990526 0.0986085 0.0997935 0.118905
3 apply+diff2 0.242721 0.2464115 0.2495150 0.2485575 0.2513510 0.295441
2 apply+diff 0.684756 0.6932470 0.7055857 0.6986960 0.7083670 1.001963
expr min lq mean median uq max
1 rowDiffs 1.000000 1.000000 1.000000 1.00000 1.000000 1.000000
4 diff + t 9.573061 9.007717 8.802592 8.87805 8.696222 6.045915
3 apply+diff2 24.325616 22.771601 22.173864 22.37845 21.903272 15.022169
2 apply+diff 68.626578 64.064966 62.703900 62.90592 61.728639 50.946408

Figure: Benchmarking of colDiffs(), apply+diff(), apply+diff2() and diff() on integer+100x100 data as well as rowDiffs(), apply+diff(), apply+diff2() and diff + t() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colDiffs() and rowDiffs() 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 rowDiffs 9.978 10.821 11.25266 11.107 11.4755 19.667
1 colDiffs 9.920 10.906 11.97519 11.491 11.8260 40.385
expr min lq mean median uq max
2 rowDiffs 1.0000000 1.000000 1.00000 1.000000 1.000000 1.00000
1 colDiffs 0.9941872 1.007855 1.06421 1.034573 1.030543 2.05344

Figure: Benchmarking of colDiffs() and rowDiffs() 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 3116021 166.5    5709258 305.0  5709258 305.0
Vcells 5529701  42.2   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colDiffs = colDiffs(X), `apply+diff` = apply(X, MARGIN = 2L, FUN = diff), 
+     `apply+diff2` = apply(X, MARGIN = 2L, FUN = diff2), diff = diff(X), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3116015 166.5    5709258 305.0  5709258 305.0
Vcells 5534744  42.3   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowDiffs = rowDiffs(X), `apply+diff` = apply(X, MARGIN = 1L, FUN = diff), 
+     `apply+diff2` = apply(X, MARGIN = 1L, FUN = diff2), `diff + t` = diff(t(X)), unit = "ms")

Table: Benchmarking of colDiffs(), apply+diff(), apply+diff2() and diff() 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 colDiffs 0.009307 0.0100455 0.0109699 0.0106900 0.0109750 0.036485
4 diff 0.082318 0.0840605 0.0856559 0.0849475 0.0860415 0.127109
3 apply+diff2 0.100588 0.1053980 0.1092378 0.1075710 0.1112395 0.154065
2 apply+diff 0.227661 0.2324470 0.2486088 0.2377635 0.2532850 0.521992
expr min lq mean median uq max
1 colDiffs 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
4 diff 8.844741 8.367976 7.808281 7.946445 7.839772 3.483870
3 apply+diff2 10.807779 10.492061 9.957978 10.062769 10.135718 4.222694
2 apply+diff 24.461266 23.139416 22.662851 22.241674 23.078360 14.307030

Table: Benchmarking of rowDiffs(), apply+diff(), apply+diff2() and diff + t() 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 rowDiffs 0.009678 0.0105085 0.0110044 0.0110370 0.0112580 0.015880
4 diff + t 0.096710 0.0994460 0.1012975 0.1001915 0.1014715 0.181647
3 apply+diff2 0.102084 0.1054135 0.1094620 0.1084810 0.1118010 0.137666
2 apply+diff 0.229195 0.2330665 0.2446532 0.2421940 0.2529835 0.311863
expr min lq mean median uq max
1 rowDiffs 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
4 diff + t 9.992767 9.463387 9.205176 9.077784 9.013279 11.438728
3 apply+diff2 10.548047 10.031260 9.947104 9.828848 9.930805 8.669144
2 apply+diff 23.682062 22.178855 22.232288 21.943825 22.471442 19.638728

Figure: Benchmarking of colDiffs(), apply+diff(), apply+diff2() and diff() on integer+1000x10 data as well as rowDiffs(), apply+diff(), apply+diff2() and diff + t() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colDiffs() and rowDiffs() 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 colDiffs 9.307 10.0455 10.96988 10.690 10.975 36.485
2 rowDiffs 9.678 10.5085 11.00441 11.037 11.258 15.880
expr min lq mean median uq max
1 colDiffs 1.000000 1.00000 1.000000 1.00000 1.000000 1.0000000
2 rowDiffs 1.039862 1.04609 1.003148 1.03246 1.025786 0.4352474

Figure: Benchmarking of colDiffs() and rowDiffs() 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 3116246 166.5    5709258 305.0  5709258 305.0
Vcells 5530519  42.2   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colDiffs = colDiffs(X), `apply+diff` = apply(X, MARGIN = 2L, FUN = diff), 
+     `apply+diff2` = apply(X, MARGIN = 2L, FUN = diff2), diff = diff(X), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3116237 166.5    5709258 305.0  5709258 305.0
Vcells 5535557  42.3   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowDiffs = rowDiffs(X), `apply+diff` = apply(X, MARGIN = 1L, FUN = diff), 
+     `apply+diff2` = apply(X, MARGIN = 1L, FUN = diff2), `diff + t` = diff(t(X)), unit = "ms")

Table: Benchmarking of colDiffs(), apply+diff(), apply+diff2() and diff() 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 colDiffs 0.009235 0.0105635 0.0118427 0.011557 0.012477 0.019136
4 diff 0.077194 0.0802685 0.0858791 0.083122 0.085378 0.143532
3 apply+diff2 1.591354 1.6218525 1.8159368 1.654945 1.714163 6.441504
2 apply+diff 4.965706 5.1157700 5.3844286 5.245360 5.439525 10.323822
expr min lq mean median uq max
1 colDiffs 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
4 diff 8.358852 7.598665 7.251652 7.192351 6.842831 7.500627
3 apply+diff2 172.317704 153.533630 153.338072 143.198451 137.385790 336.617057
2 apply+diff 537.705035 484.287405 454.662244 453.868608 435.964174 539.497387

Table: Benchmarking of rowDiffs(), apply+diff(), apply+diff2() and diff + t() 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 rowDiffs 0.008907 0.0099930 0.0113299 0.0109580 0.0121565 0.017723
4 diff + t 0.091877 0.0947805 0.1032366 0.0990875 0.1057695 0.175348
3 apply+diff2 1.585711 1.6161850 1.6896580 1.6660525 1.7329050 1.980962
2 apply+diff 4.929119 5.0946145 5.4897445 5.2661250 5.4027555 10.473003
expr min lq mean median uq max
1 rowDiffs 1.00000 1.000000 1.000000 1.00000 1.000000 1.00000
4 diff + t 10.31515 9.484689 9.111847 9.04248 8.700654 9.89381
3 apply+diff2 178.02975 161.731712 149.132254 152.03983 142.549665 111.77351
2 apply+diff 553.39834 509.818323 484.534720 480.57355 444.433472 590.92721

Figure: Benchmarking of colDiffs(), apply+diff(), apply+diff2() and diff() on integer+10x1000 data as well as rowDiffs(), apply+diff(), apply+diff2() and diff + t() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colDiffs() and rowDiffs() 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
2 rowDiffs 8.907 9.9930 11.32993 10.958 12.1565 17.723
1 colDiffs 9.235 10.5635 11.84270 11.557 12.4770 19.136
expr min lq mean median uq max
2 rowDiffs 1.000000 1.00000 1.000000 1.000000 1.000000 1.000000
1 colDiffs 1.036825 1.05709 1.045258 1.054663 1.026364 1.079727

Figure: Benchmarking of colDiffs() and rowDiffs() 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 3116469 166.5    5709258 305.0  5709258 305.0
Vcells 5531104  42.2   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colDiffs = colDiffs(X), `apply+diff` = apply(X, MARGIN = 2L, FUN = diff), 
+     `apply+diff2` = apply(X, MARGIN = 2L, FUN = diff2), diff = diff(X), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3116460 166.5    5709258 305.0  5709258 305.0
Vcells 5581142  42.6   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowDiffs = rowDiffs(X), `apply+diff` = apply(X, MARGIN = 1L, FUN = diff), 
+     `apply+diff2` = apply(X, MARGIN = 1L, FUN = diff2), `diff + t` = diff(t(X)), unit = "ms")

Table: Benchmarking of colDiffs(), apply+diff(), apply+diff2() and diff() 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 colDiffs 0.087169 0.0925755 0.0985038 0.096522 0.1007805 0.21958
4 diff 0.742494 0.7553605 1.0954965 0.777774 0.8358645 15.65912
3 apply+diff2 2.240516 2.3055240 2.5490086 2.351670 2.4236410 16.39443
2 apply+diff 6.619139 6.8144420 7.5455161 6.957101 7.2693915 22.61019
expr min lq mean median uq max
1 colDiffs 1.000000 1.00000 1.00000 1.000000 1.000000 1.00000
4 diff 8.517868 8.15940 11.12136 8.057997 8.293911 71.31398
3 apply+diff2 25.703128 24.90426 25.87725 24.364088 24.048710 74.66268
2 apply+diff 75.934552 73.60956 76.60125 72.077873 72.130933 102.97016

Table: Benchmarking of rowDiffs(), apply+diff(), apply+diff2() and diff + t() 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 rowDiffs 0.080714 0.085084 0.2295152 0.088314 0.0927070 13.38035
4 diff + t 0.856953 0.890669 1.2247585 0.915878 0.9646175 15.19377
3 apply+diff2 2.246759 2.315821 2.7450913 2.377005 2.4885400 17.32280
2 apply+diff 6.627130 6.754207 9.8319702 6.929648 7.4608230 252.47289
expr min lq mean median uq max
1 rowDiffs 1.00000 1.00000 1.000000 1.00000 1.00000 1.000000
4 diff + t 10.61715 10.46811 5.336284 10.37070 10.40501 1.135528
3 apply+diff2 27.83605 27.21805 11.960389 26.91538 26.84306 1.294645
2 apply+diff 82.10633 79.38281 42.837988 78.46602 80.47745 18.868932

Figure: Benchmarking of colDiffs(), apply+diff(), apply+diff2() and diff() on integer+100x1000 data as well as rowDiffs(), apply+diff(), apply+diff2() and diff + t() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colDiffs() and rowDiffs() 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
2 rowDiffs 80.714 85.0840 229.51522 88.314 92.7070 13380.35
1 colDiffs 87.169 92.5755 98.50383 96.522 100.7805 219.58
expr min lq mean median uq max
2 rowDiffs 1.000000 1.000000 1.0000000 1.000000 1.000000 1.0000000
1 colDiffs 1.079974 1.088048 0.4291821 1.092941 1.087086 0.0164106

Figure: Benchmarking of colDiffs() and rowDiffs() 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 3116702 166.5    5709258 305.0  5709258 305.0
Vcells 5531789  42.3   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colDiffs = colDiffs(X), `apply+diff` = apply(X, MARGIN = 2L, FUN = diff), 
+     `apply+diff2` = apply(X, MARGIN = 2L, FUN = diff2), diff = diff(X), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3116693 166.5    5709258 305.0  5709258 305.0
Vcells 5581827  42.6   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowDiffs = rowDiffs(X), `apply+diff` = apply(X, MARGIN = 1L, FUN = diff), 
+     `apply+diff2` = apply(X, MARGIN = 1L, FUN = diff2), `diff + t` = diff(t(X)), unit = "ms")

Table: Benchmarking of colDiffs(), apply+diff(), apply+diff2() and diff() 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 colDiffs 0.081767 0.0857730 0.0929655 0.0910595 0.0988515 0.114236
4 diff 0.738713 0.7458715 0.8026512 0.7582425 0.8596720 1.034397
3 apply+diff2 0.837349 0.8475045 0.9754013 0.8719135 0.9433095 7.770486
2 apply+diff 2.097026 2.1284360 2.6722813 2.2429140 2.5575960 9.666034
expr min lq mean median uq max
1 colDiffs 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
4 diff 9.034366 8.695877 8.633864 8.326891 8.696601 9.054913
3 apply+diff2 10.240672 9.880784 10.492082 9.575206 9.542693 68.021342
2 apply+diff 25.646361 24.814755 28.744880 24.631301 25.873113 84.614605

Table: Benchmarking of rowDiffs(), apply+diff(), apply+diff2() and diff + t() 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 rowDiffs 0.086141 0.0880170 0.0940816 0.0900150 0.096867 0.128768
4 diff + t 0.871176 0.8827525 1.0105405 0.9042490 1.000484 7.358402
3 apply+diff2 0.870173 0.8794700 1.0184523 0.9163815 1.006802 7.316249
2 apply+diff 2.125665 2.1449170 2.6449411 2.1888180 2.536551 9.075185
expr min lq mean median uq max
1 rowDiffs 1.00000 1.000000 1.00000 1.00000 1.00000 1.00000
4 diff + t 10.11337 10.029341 10.74111 10.04554 10.32842 57.14465
3 apply+diff2 10.10173 9.992047 10.82520 10.18032 10.39365 56.81729
2 apply+diff 24.67658 24.369349 28.11327 24.31615 26.18591 70.47702

Figure: Benchmarking of colDiffs(), apply+diff(), apply+diff2() and diff() on integer+1000x100 data as well as rowDiffs(), apply+diff(), apply+diff2() and diff + t() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colDiffs() and rowDiffs() 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
2 rowDiffs 86.141 88.017 94.08158 90.0150 96.8670 128.768
1 colDiffs 81.767 85.773 92.96547 91.0595 98.8515 114.236
expr min lq mean median uq max
2 rowDiffs 1.0000000 1.0000000 1.0000000 1.000000 1.000000 1.0000000
1 colDiffs 0.9492228 0.9745049 0.9881368 1.011604 1.020487 0.8871459

Figure: Benchmarking of colDiffs() and rowDiffs() 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 3116941 166.5    5709258 305.0  5709258 305.0
Vcells 5648432  43.1   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colDiffs = colDiffs(X), `apply+diff` = apply(X, MARGIN = 2L, FUN = diff), 
+     `apply+diff2` = apply(X, MARGIN = 2L, FUN = diff2), diff = diff(X), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3116923 166.5    5709258 305.0  5709258 305.0
Vcells 5648555  43.1   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowDiffs = rowDiffs(X), `apply+diff` = apply(X, MARGIN = 1L, FUN = diff), 
+     `apply+diff2` = apply(X, MARGIN = 1L, FUN = diff2), `diff + t` = diff(t(X)), unit = "ms")

Table: Benchmarking of colDiffs(), apply+diff(), apply+diff2() and diff() 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 colDiffs 0.001332 0.0017685 0.0021764 0.002117 0.0023290 0.012753
4 diff 0.006683 0.0074415 0.0087978 0.008487 0.0088460 0.063720
3 apply+diff2 0.033904 0.0349200 0.0356623 0.035278 0.0356905 0.046555
2 apply+diff 0.068321 0.0694755 0.0710144 0.069875 0.0705875 0.130362
expr min lq mean median uq max
1 colDiffs 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
4 diff 5.017267 4.207803 4.042382 4.008975 3.798197 4.996471
3 apply+diff2 25.453453 19.745547 16.386045 16.664147 15.324388 3.650514
2 apply+diff 51.292042 39.284987 32.629591 33.006613 30.308072 10.222065

Table: Benchmarking of rowDiffs(), apply+diff(), apply+diff2() and diff + t() 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 rowDiffs 0.001196 0.0016925 0.0020263 0.0020565 0.0022110 0.006898
4 diff + t 0.008912 0.0101180 0.0112274 0.0113460 0.0118790 0.028226
3 apply+diff2 0.033201 0.0339955 0.0352648 0.0343690 0.0348130 0.109465
2 apply+diff 0.067129 0.0680925 0.0695140 0.0686705 0.0695905 0.092455
expr min lq mean median uq max
1 rowDiffs 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
4 diff + t 7.451505 5.978139 5.540714 5.517141 5.372682 4.091911
3 apply+diff2 27.760033 20.085967 17.403200 16.712375 15.745364 15.869093
2 apply+diff 56.127926 40.231906 34.305186 33.391928 31.474672 13.403160

Figure: Benchmarking of colDiffs(), apply+diff(), apply+diff2() and diff() on double+10x10 data as well as rowDiffs(), apply+diff(), apply+diff2() and diff + t() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colDiffs() and rowDiffs() 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 rowDiffs 1.196 1.6925 2.02634 2.0565 2.211 6.898
1 colDiffs 1.332 1.7685 2.17638 2.1170 2.329 12.753
expr min lq mean median uq max
2 rowDiffs 1.000000 1.000000 1.000000 1.000000 1.00000 1.000000
1 colDiffs 1.113712 1.044904 1.074045 1.029419 1.05337 1.848797

Figure: Benchmarking of colDiffs() and rowDiffs() 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 3117158 166.5    5709258 305.0  5709258 305.0
Vcells 5648569  43.1   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colDiffs = colDiffs(X), `apply+diff` = apply(X, MARGIN = 2L, FUN = diff), 
+     `apply+diff2` = apply(X, MARGIN = 2L, FUN = diff2), diff = diff(X), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3117149 166.5    5709258 305.0  5709258 305.0
Vcells 5658607  43.2   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowDiffs = rowDiffs(X), `apply+diff` = apply(X, MARGIN = 1L, FUN = diff), 
+     `apply+diff2` = apply(X, MARGIN = 1L, FUN = diff2), `diff + t` = diff(t(X)), unit = "ms")

Table: Benchmarking of colDiffs(), apply+diff(), apply+diff2() and diff() 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 colDiffs 0.007826 0.0089330 0.0109103 0.0093670 0.0101715 0.105528
4 diff 0.072652 0.0745505 0.0822667 0.0759545 0.0807860 0.293838
3 apply+diff2 0.281168 0.2854040 0.2985432 0.2890935 0.2951325 0.475516
2 apply+diff 0.683353 0.6971835 0.8540302 0.7070430 0.7260250 12.893743
expr min lq mean median uq max
1 colDiffs 1.000000 1.000000 1.00000 1.000000 1.000000 1.000000
4 diff 9.283414 8.345517 7.54030 8.108733 7.942388 2.784455
3 apply+diff2 35.927421 31.949401 27.36350 30.862976 29.015632 4.506065
2 apply+diff 87.318298 78.045841 78.27764 75.482332 71.378361 122.183146

Table: Benchmarking of rowDiffs(), apply+diff(), apply+diff2() and diff + t() 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 rowDiffs 0.007596 0.0088750 0.0105745 0.0094270 0.0118065 0.022192
4 diff + t 0.053961 0.0564360 0.2286574 0.0583420 0.0693790 16.516990
3 apply+diff2 0.240055 0.2433520 0.2666842 0.2464280 0.2586960 0.449597
2 apply+diff 0.642614 0.6501085 0.6950446 0.6604355 0.6884510 1.091673
expr min lq mean median uq max
1 rowDiffs 1.000000 1.000000 1.00000 1.000000 1.000000 1.00000
4 diff + t 7.103871 6.358986 21.62343 6.188819 5.876339 744.27677
3 apply+diff2 31.602817 27.419944 25.21951 26.140660 21.911320 20.25942
2 apply+diff 84.599000 73.251662 65.72824 70.057866 58.311185 49.19219

Figure: Benchmarking of colDiffs(), apply+diff(), apply+diff2() and diff() on double+100x100 data as well as rowDiffs(), apply+diff(), apply+diff2() and diff + t() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colDiffs() and rowDiffs() 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 colDiffs 7.826 8.933 10.91027 9.367 10.1715 105.528
2 rowDiffs 7.596 8.875 10.57452 9.427 11.8065 22.192
expr min lq mean median uq max
1 colDiffs 1.0000000 1.0000000 1.0000000 1.000000 1.000000 1.0000000
2 rowDiffs 0.9706108 0.9935072 0.9692262 1.006406 1.160743 0.2102949

Figure: Benchmarking of colDiffs() and rowDiffs() 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 3117384 166.5    5709258 305.0  5709258 305.0
Vcells 5649631  43.2   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colDiffs = colDiffs(X), `apply+diff` = apply(X, MARGIN = 2L, FUN = diff), 
+     `apply+diff2` = apply(X, MARGIN = 2L, FUN = diff2), diff = diff(X), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3117375 166.5    5709258 305.0  5709258 305.0
Vcells 5659669  43.2   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowDiffs = rowDiffs(X), `apply+diff` = apply(X, MARGIN = 1L, FUN = diff), 
+     `apply+diff2` = apply(X, MARGIN = 1L, FUN = diff2), `diff + t` = diff(t(X)), unit = "ms")

Table: Benchmarking of colDiffs(), apply+diff(), apply+diff2() and diff() 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 colDiffs 0.007905 0.0086945 0.0095011 0.0090655 0.0097005 0.021953
4 diff 0.073266 0.0750120 0.0781225 0.0760670 0.0769490 0.111926
3 apply+diff2 0.145058 0.1481450 0.1536575 0.1499690 0.1534765 0.201126
2 apply+diff 0.230347 0.2374750 0.3072987 0.2439350 0.2505075 5.969996
expr min lq mean median uq max
1 colDiffs 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
4 diff 9.268311 8.627523 8.222441 8.390822 7.932478 5.098438
3 apply+diff2 18.350158 17.038933 16.172552 16.542827 15.821504 9.161664
2 apply+diff 29.139405 27.313244 32.343387 26.908058 25.824184 271.944427

Table: Benchmarking of rowDiffs(), apply+diff(), apply+diff2() and diff + t() 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 rowDiffs 0.007774 0.0087175 0.0093711 0.009075 0.0095330 0.018593
4 diff + t 0.054855 0.0570195 0.1176786 0.058473 0.0606920 5.704849
3 apply+diff2 0.104058 0.1081360 0.1146844 0.110227 0.1172655 0.178295
2 apply+diff 0.191114 0.1957605 0.2085546 0.205078 0.2111210 0.291587
expr min lq mean median uq max
1 rowDiffs 1.000000 1.000000 1.00000 1.000000 1.000000 1.000000
4 diff + t 7.056213 6.540809 12.55755 6.443306 6.366516 306.827785
3 apply+diff2 13.385387 12.404474 12.23804 12.146226 12.301007 9.589362
2 apply+diff 24.583741 22.456037 22.25499 22.598127 22.146334 15.682623

Figure: Benchmarking of colDiffs(), apply+diff(), apply+diff2() and diff() on double+1000x10 data as well as rowDiffs(), apply+diff(), apply+diff2() and diff + t() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colDiffs() and rowDiffs() 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 colDiffs 7.905 8.6945 9.50113 9.0655 9.7005 21.953
2 rowDiffs 7.774 8.7175 9.37114 9.0750 9.5330 18.593
expr min lq mean median uq max
1 colDiffs 1.0000000 1.000000 1.0000000 1.000000 1.0000000 1.0000000
2 rowDiffs 0.9834282 1.002645 0.9863185 1.001048 0.9827328 0.8469457

Figure: Benchmarking of colDiffs() and rowDiffs() 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 3117606 166.5    5709258 305.0  5709258 305.0
Vcells 5650870  43.2   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colDiffs = colDiffs(X), `apply+diff` = apply(X, MARGIN = 2L, FUN = diff), 
+     `apply+diff2` = apply(X, MARGIN = 2L, FUN = diff2), diff = diff(X), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3117597 166.5    5709258 305.0  5709258 305.0
Vcells 5660908  43.2   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowDiffs = rowDiffs(X), `apply+diff` = apply(X, MARGIN = 1L, FUN = diff), 
+     `apply+diff2` = apply(X, MARGIN = 1L, FUN = diff2), `diff + t` = diff(t(X)), unit = "ms")

Table: Benchmarking of colDiffs(), apply+diff(), apply+diff2() and diff() 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 colDiffs 0.007948 0.0106020 0.0129899 0.0123225 0.013964 0.029984
4 diff 0.039178 0.0426205 0.0475171 0.0455745 0.048588 0.090872
3 apply+diff2 1.579078 1.6598810 1.8660162 1.7064235 1.770217 6.770882
2 apply+diff 4.886083 5.3134105 5.5818545 5.5080760 5.673311 10.608300
expr min lq mean median uq max
1 colDiffs 1.00000 1.000000 1.000000 1.000000 1.000000 1.000000
4 diff 4.92929 4.020043 3.658018 3.698478 3.479519 3.030683
3 apply+diff2 198.67614 156.563007 143.651758 138.480300 126.770087 225.816502
2 apply+diff 614.75629 501.170581 429.708594 446.993386 406.281223 353.798693

Table: Benchmarking of rowDiffs(), apply+diff(), apply+diff2() and diff + t() 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 rowDiffs 0.007831 0.0105750 0.0123780 0.0119180 0.0135355 0.023236
4 diff + t 0.054646 0.0583525 0.0655831 0.0626105 0.0692040 0.140861
3 apply+diff2 1.576733 1.6441280 1.7074512 1.6826055 1.7476215 1.966085
2 apply+diff 4.970668 5.2324175 5.6254805 5.3840850 5.6055665 11.002043
expr min lq mean median uq max
1 rowDiffs 1.000000 1.000000 1.000000 1.00000 1.000000 1.000000
4 diff + t 6.978164 5.517967 5.298349 5.25344 5.112777 6.062188
3 apply+diff2 201.345039 155.473097 137.942194 141.18187 129.113923 84.613746
2 apply+diff 634.742434 494.791253 454.473370 451.76078 414.138118 473.491264

Figure: Benchmarking of colDiffs(), apply+diff(), apply+diff2() and diff() on double+10x1000 data as well as rowDiffs(), apply+diff(), apply+diff2() and diff + t() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colDiffs() and rowDiffs() 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 rowDiffs 7.831 10.575 12.37802 11.9180 13.5355 23.236
1 colDiffs 7.948 10.602 12.98986 12.3225 13.9640 29.984
expr min lq mean median uq max
2 rowDiffs 1.000000 1.000000 1.00000 1.00000 1.000000 1.000000
1 colDiffs 1.014941 1.002553 1.04943 1.03394 1.031657 1.290411

Figure: Benchmarking of colDiffs() and rowDiffs() 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 3117829 166.6    5709258 305.0  5709258 305.0
Vcells 5651018  43.2   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colDiffs = colDiffs(X), `apply+diff` = apply(X, MARGIN = 2L, FUN = diff), 
+     `apply+diff2` = apply(X, MARGIN = 2L, FUN = diff2), diff = diff(X), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3117820 166.6    5709258 305.0  5709258 305.0
Vcells 5751056  43.9   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowDiffs = rowDiffs(X), `apply+diff` = apply(X, MARGIN = 1L, FUN = diff), 
+     `apply+diff2` = apply(X, MARGIN = 1L, FUN = diff2), `diff + t` = diff(t(X)), unit = "ms")

Table: Benchmarking of colDiffs(), apply+diff(), apply+diff2() and diff() 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 colDiffs 0.068753 0.0809590 0.2186692 0.0936815 0.1062405 11.97728
4 diff 0.671257 0.6902585 0.8713896 0.7059570 0.8116290 12.64426
3 apply+diff2 2.657512 2.7096860 3.3058297 2.7729975 3.2179400 15.45456
2 apply+diff 6.709998 6.8670360 8.1240188 7.1100785 7.9345530 20.51747
expr min lq mean median uq max
1 colDiffs 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
4 diff 9.763312 8.526025 3.984967 7.535714 7.639544 1.055687
3 apply+diff2 38.653033 33.469855 15.117947 29.600268 30.289202 1.290323
2 apply+diff 97.595712 84.821156 37.152091 75.896292 74.684824 1.713032

Table: Benchmarking of rowDiffs(), apply+diff(), apply+diff2() and diff + t() 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 rowDiffs 0.068515 0.0820635 0.1000359 0.091831 0.101646 0.266283
4 diff + t 0.454952 0.5172565 0.6786516 0.546358 0.598187 12.250272
3 apply+diff2 2.284115 2.3557905 3.1236122 2.572386 2.977993 15.632607
2 apply+diff 6.343725 6.5136880 8.2095237 7.187853 8.147941 22.801852
expr min lq mean median uq max
1 rowDiffs 1.000000 1.000000 1.00000 1.000000 1.000000 1.00000
4 diff + t 6.640181 6.303125 6.78408 5.949603 5.885003 46.00471
3 apply+diff2 33.337444 28.706922 31.22491 28.012169 29.297690 58.70674
2 apply+diff 92.588849 79.373753 82.06578 78.272620 80.159972 85.63015

Figure: Benchmarking of colDiffs(), apply+diff(), apply+diff2() and diff() on double+100x1000 data as well as rowDiffs(), apply+diff(), apply+diff2() and diff + t() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colDiffs() and rowDiffs() 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 rowDiffs 68.515 82.0635 100.0359 91.8310 101.6460 266.283
1 colDiffs 68.753 80.9590 218.6692 93.6815 106.2405 11977.281
expr min lq mean median uq max
2 rowDiffs 1.000000 1.0000000 1.000000 1.000000 1.000000 1.00000
1 colDiffs 1.003474 0.9865409 2.185907 1.020151 1.045201 44.97952

Figure: Benchmarking of colDiffs() and rowDiffs() 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 3118062 166.6    5709258 305.0  5709258 305.0
Vcells 5652492  43.2   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colDiffs = colDiffs(X), `apply+diff` = apply(X, MARGIN = 2L, FUN = diff), 
+     `apply+diff2` = apply(X, MARGIN = 2L, FUN = diff2), diff = diff(X), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3118053 166.6    5709258 305.0  5709258 305.0
Vcells 5752530  43.9   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowDiffs = rowDiffs(X), `apply+diff` = apply(X, MARGIN = 1L, FUN = diff), 
+     `apply+diff2` = apply(X, MARGIN = 1L, FUN = diff2), `diff + t` = diff(t(X)), unit = "ms")

Table: Benchmarking of colDiffs(), apply+diff(), apply+diff2() and diff() 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 colDiffs 0.067611 0.0821295 0.0927182 0.088574 0.1024565 0.134425
4 diff 0.341218 0.3933645 0.5556137 0.421854 0.4479860 7.588598
3 apply+diff2 0.891035 1.0466215 1.2835500 1.109388 1.1563550 7.021451
2 apply+diff 1.739943 2.1044035 2.6775548 2.251618 2.4016450 14.261253
expr min lq mean median uq max
1 colDiffs 1.000000 1.000000 1.000000 1.000000 1.000000 1.00000
4 diff 5.046782 4.789564 5.992501 4.762729 4.372451 56.45228
3 apply+diff2 13.178847 12.743551 13.843564 12.524985 11.286302 52.23322
2 apply+diff 25.734614 25.622992 28.878426 25.420750 23.440631 106.09078

Table: Benchmarking of rowDiffs(), apply+diff(), apply+diff2() and diff + t() 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 rowDiffs 0.069929 0.0835605 0.1677974 0.0925420 0.1084595 6.896821
4 diff + t 0.460530 0.5702410 0.6175363 0.5985205 0.6342225 1.395840
3 apply+diff2 0.902764 1.0965220 1.4181183 1.1716210 1.2517770 7.471189
2 apply+diff 1.802847 2.2327080 2.8208954 2.3852495 2.5657390 10.253641
expr min lq mean median uq max
1 rowDiffs 1.00000 1.000000 1.000000 1.000000 1.000000 1.0000000
4 diff + t 6.58568 6.824289 3.680250 6.467555 5.847551 0.2023889
3 apply+diff2 12.90972 13.122492 8.451373 12.660424 11.541423 1.0832801
2 apply+diff 25.78111 26.719658 16.811320 25.774778 23.656194 1.4867199

Figure: Benchmarking of colDiffs(), apply+diff(), apply+diff2() and diff() on double+1000x100 data as well as rowDiffs(), apply+diff(), apply+diff2() and diff + t() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colDiffs() and rowDiffs() 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 colDiffs 67.611 82.1295 92.71817 88.574 102.4565 134.425
2 rowDiffs 69.929 83.5605 167.79738 92.542 108.4595 6896.821
expr min lq mean median uq max
1 colDiffs 1.000000 1.000000 1.000000 1.000000 1.000000 1.00000
2 rowDiffs 1.034284 1.017424 1.809757 1.044799 1.058591 51.30609

Figure: Benchmarking of colDiffs() and rowDiffs() 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 35.3 secs.

Reproducibility

To reproduce this report, do:

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

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