-
Notifications
You must be signed in to change notification settings - Fork 0
colRowDiffs
matrixStats: Benchmark report
This report benchmark the performance of colDiffs() and rowDiffs() against alternative methods.
- apply() + diff()
- apply() + diff2()
- diff()
> rmatrix <- function(nrow, ncol, mode = c("logical", "double", "integer", "index"), range = c(-100,
+ +100), naProb = 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 (naProb > 0)
+ X[sample(n, size = naProb * 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)> X <- data[["10x10"]]
> gc()
used (Mb) gc trigger (Mb) max used (Mb)
Ncells 652121 34.9 1168576 62.5 1168576 62.5
Vcells 12127277 92.6 35610798 271.7 68120027 519.8
> 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 651609 34.8 1168576 62.5 1168576 62.5
Vcells 12126201 92.6 35610798 271.7 68120027 519.8
> 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.0023 | 0.0050 | 0.0073 | 0.0060 | 0.0077 | 0.1120 |
| 4 | diff | 0.0158 | 0.0196 | 0.0247 | 0.0235 | 0.0262 | 0.0801 |
| 3 | apply+diff2 | 0.0932 | 0.0974 | 0.1210 | 0.1005 | 0.1497 | 0.6698 |
| 2 | apply+diff | 0.1871 | 0.1952 | 0.2284 | 0.1984 | 0.2931 | 0.3110 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | colDiffs | 1.00 | 1.000 | 1.000 | 1.000 | 1.00 | 1.0000 |
| 4 | diff | 6.83 | 3.922 | 3.391 | 3.935 | 3.40 | 0.7148 |
| 3 | apply+diff2 | 40.31 | 19.457 | 16.608 | 16.835 | 19.45 | 5.9794 |
| 2 | apply+diff | 80.96 | 38.992 | 31.336 | 33.252 | 38.07 | 2.7766 |
| 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.0019 | 0.0035 | 0.0079 | 0.0058 | 0.0083 | 0.1440 |
| 4 | diff + t | 0.0239 | 0.0327 | 0.0418 | 0.0356 | 0.0493 | 0.1190 |
| 3 | apply+diff2 | 0.0932 | 0.0982 | 0.1226 | 0.1007 | 0.1644 | 0.2140 |
| 2 | apply+diff | 0.1863 | 0.1952 | 0.2456 | 0.1977 | 0.3239 | 0.5466 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | rowDiffs | 1.00 | 1.000 | 1.000 | 1.000 | 1.000 | 1.0000 |
| 4 | diff + t | 12.39 | 9.444 | 5.291 | 6.166 | 5.953 | 0.8262 |
| 3 | apply+diff2 | 48.37 | 28.330 | 15.540 | 17.431 | 19.858 | 1.4866 |
| 2 | apply+diff | 96.74 | 56.327 | 31.115 | 34.229 | 39.135 | 3.7968 |
| 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.926 | 3.465 | 7.893 | 5.775 | 8.277 | 144 |
| 1 | colDiffs | 2.311 | 5.005 | 7.288 | 5.968 | 7.700 | 112 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 2 | rowDiffs | 1.0 | 1.000 | 1.0000 | 1.000 | 1.0000 | 1.0000 |
| 1 | colDiffs | 1.2 | 1.445 | 0.9234 | 1.033 | 0.9302 | 0.7781 |
| Figure: Benchmarking of colDiffs() and rowDiffs() on integer+10x10 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds. |

> X <- data[["100x100"]]
> gc()
used (Mb) gc trigger (Mb) max used (Mb)
Ncells 651707 34.9 1168576 62.5 1168576 62.5
Vcells 12127600 92.6 35610798 271.7 68120027 519.8
> 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 651701 34.9 1168576 62.5 1168576 62.5
Vcells 12132643 92.6 35610798 271.7 68120027 519.8
> 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.0212 | 0.0389 | 0.0459 | 0.0456 | 0.0545 | 0.0674 |
| 4 | diff | 0.1963 | 0.2352 | 0.2914 | 0.2910 | 0.3336 | 0.4492 |
| 3 | apply+diff2 | 0.7360 | 0.8313 | 1.2553 | 1.2848 | 1.3776 | 12.5830 |
| 2 | apply+diff | 1.8878 | 2.0122 | 2.7597 | 3.0379 | 3.2109 | 10.8445 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | colDiffs | 1.000 | 1.000 | 1.000 | 1.00 | 1.000 | 1.000 |
| 4 | diff | 9.273 | 6.049 | 6.354 | 6.38 | 6.124 | 6.668 |
| 3 | apply+diff2 | 34.763 | 21.381 | 27.365 | 28.16 | 25.290 | 186.780 |
| 2 | apply+diff | 89.161 | 51.752 | 60.161 | 66.59 | 58.946 | 160.975 |
| 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.0208 | 0.0416 | 0.0508 | 0.0527 | 0.0602 | 0.0716 |
| 4 | diff + t | 0.2275 | 0.3199 | 0.3680 | 0.3759 | 0.4275 | 0.5436 |
| 3 | apply+diff2 | 0.8165 | 1.3289 | 1.4804 | 1.3960 | 1.4732 | 13.0218 |
| 2 | apply+diff | 2.0745 | 3.1376 | 3.3738 | 3.3146 | 3.4390 | 14.8169 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | rowDiffs | 1.00 | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 |
| 4 | diff + t | 10.94 | 7.694 | 7.245 | 7.128 | 7.096 | 7.591 |
| 3 | apply+diff2 | 39.28 | 31.962 | 29.148 | 26.470 | 24.453 | 181.864 |
| 2 | apply+diff | 99.79 | 75.466 | 66.430 | 62.849 | 57.082 | 206.934 |
| 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 |
|---|---|---|---|---|---|---|
| colDiffs | 21.17 | 38.88 | 45.87 | 45.62 | 54.47 | 67.37 |
| rowDiffs | 20.79 | 41.58 | 50.79 | 52.74 | 60.25 | 71.60 |
| expr | min | lq | mean | median | uq | max |
|---|---|---|---|---|---|---|
| colDiffs | 1.0000 | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 |
| rowDiffs | 0.9818 | 1.069 | 1.107 | 1.156 | 1.106 | 1.063 |
| Figure: Benchmarking of colDiffs() and rowDiffs() on integer+100x100 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds. |

> X <- data[["1000x10"]]
> gc()
used (Mb) gc trigger (Mb) max used (Mb)
Ncells 651746 34.9 1168576 62.5 1168576 62.5
Vcells 12127838 92.6 35610798 271.7 68120027 519.8
> 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 651740 34.9 1168576 62.5 1168576 62.5
Vcells 12132881 92.6 35610798 271.7 68120027 519.8
> 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.0196 | 0.0277 | 0.0393 | 0.0391 | 0.0477 | 0.0631 |
| 4 | diff | 0.2048 | 0.2173 | 0.3008 | 0.3218 | 0.3630 | 0.5085 |
| 3 | apply+diff2 | 0.3896 | 0.4733 | 0.6279 | 0.6802 | 0.7322 | 1.2319 |
| 2 | apply+diff | 0.6775 | 0.7674 | 1.0440 | 1.1435 | 1.2093 | 1.3585 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | colDiffs | 1.00 | 1.00 | 1.000 | 1.000 | 1.000 | 1.000 |
| 4 | diff | 10.43 | 7.84 | 7.664 | 8.236 | 7.605 | 8.055 |
| 3 | apply+diff2 | 19.84 | 17.08 | 15.996 | 17.409 | 15.338 | 19.512 |
| 2 | apply+diff | 34.51 | 27.69 | 26.597 | 29.265 | 25.334 | 21.518 |
| 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.0239 | 0.0308 | 0.0408 | 0.0431 | 0.0485 | 0.0685 |
| 4 | diff + t | 0.2360 | 0.2572 | 0.3070 | 0.3124 | 0.3430 | 0.4912 |
| 3 | apply+diff2 | 0.3884 | 0.4702 | 0.5599 | 0.5951 | 0.6406 | 0.7484 |
| 2 | apply+diff | 0.6833 | 0.7191 | 0.9294 | 0.9941 | 1.0867 | 1.2696 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | rowDiffs | 1.000 | 1.00 | 1.000 | 1.000 | 1.000 | 1.000 |
| 4 | diff + t | 9.887 | 8.35 | 7.527 | 7.245 | 7.071 | 7.168 |
| 3 | apply+diff2 | 16.274 | 15.27 | 13.728 | 13.803 | 13.206 | 10.921 |
| 2 | apply+diff | 28.628 | 23.35 | 22.786 | 23.057 | 22.404 | 18.528 |
| 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 |
|---|---|---|---|---|---|---|
| colDiffs | 19.63 | 27.72 | 39.25 | 39.07 | 47.73 | 63.13 |
| rowDiffs | 23.87 | 30.80 | 40.79 | 43.12 | 48.51 | 68.52 |
| expr | min | lq | mean | median | uq | max |
|---|---|---|---|---|---|---|
| colDiffs | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 |
| rowDiffs | 1.216 | 1.111 | 1.039 | 1.103 | 1.016 | 1.085 |
| Figure: Benchmarking of colDiffs() and rowDiffs() on integer+1000x10 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds. |

> X <- data[["10x1000"]]
> gc()
used (Mb) gc trigger (Mb) max used (Mb)
Ncells 651779 34.9 1168576 62.5 1168576 62.5
Vcells 12128497 92.6 35610798 271.7 68120027 519.8
> 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 651773 34.9 1168576 62.5 1168576 62.5
Vcells 12133540 92.6 35610798 271.7 68120027 519.8
> 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.0223 | 0.0398 | 0.0466 | 0.0447 | 0.0583 | 0.0805 |
| 4 | diff | 0.1809 | 0.2171 | 0.2562 | 0.2508 | 0.2985 | 0.4789 |
| 3 | apply+diff2 | 4.0228 | 4.4108 | 7.3171 | 6.2407 | 7.4412 | 119.2660 |
| 2 | apply+diff | 13.8972 | 14.9422 | 19.4433 | 18.7034 | 22.1824 | 37.5157 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | colDiffs | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 |
| 4 | diff | 8.103 | 5.449 | 5.497 | 5.616 | 5.119 | 5.952 |
| 3 | apply+diff2 | 180.167 | 110.703 | 157.009 | 139.753 | 127.589 | 1482.376 |
| 2 | apply+diff | 622.412 | 375.022 | 417.207 | 418.841 | 380.347 | 466.288 |
| 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.0177 | 0.0325 | 0.0392 | 0.0395 | 0.0489 | 0.0631 |
| 4 | diff + t | 0.2121 | 0.2758 | 0.3019 | 0.2956 | 0.3357 | 0.4508 |
| 3 | apply+diff2 | 4.1929 | 4.5197 | 6.1341 | 5.5814 | 7.3547 | 12.0691 |
| 2 | apply+diff | 13.8668 | 14.5501 | 17.7744 | 15.4222 | 20.7244 | 32.2541 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | rowDiffs | 1.00 | 1.000 | 1.000 | 1.000 | 1.000 | 1.00 |
| 4 | diff + t | 11.98 | 8.479 | 7.707 | 7.493 | 6.866 | 7.14 |
| 3 | apply+diff2 | 236.78 | 138.943 | 156.571 | 141.451 | 150.434 | 191.17 |
| 2 | apply+diff | 783.08 | 447.289 | 453.687 | 390.846 | 423.898 | 510.88 |
| 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 | 17.71 | 32.53 | 39.18 | 39.46 | 48.89 | 63.13 |
| 1 | colDiffs | 22.33 | 39.84 | 46.60 | 44.66 | 58.32 | 80.46 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 2 | rowDiffs | 1.000 | 1.000 | 1.00 | 1.000 | 1.000 | 1.000 |
| 1 | colDiffs | 1.261 | 1.225 | 1.19 | 1.132 | 1.193 | 1.274 |
| Figure: Benchmarking of colDiffs() and rowDiffs() on integer+10x1000 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds. |

> X <- data[["100x1000"]]
> gc()
used (Mb) gc trigger (Mb) max used (Mb)
Ncells 651818 34.9 1168576 62.5 1168576 62.5
Vcells 12128910 92.6 35610798 271.7 68120027 519.8
> 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 651812 34.9 1168576 62.5 1168576 62.5
Vcells 12178953 93.0 35610798 271.7 68120027 519.8
> 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.1875 | 0.225 | 0.283 | 0.2416 | 0.3622 | 0.4269 |
| 4 | diff | 2.1750 | 2.340 | 2.862 | 2.5484 | 3.3814 | 4.5629 |
| 3 | apply+diff2 | 7.1082 | 7.572 | 10.720 | 9.7053 | 12.5422 | 29.5795 |
| 2 | apply+diff | 18.6753 | 21.836 | 27.337 | 26.7275 | 31.0019 | 43.9205 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | colDiffs | 1.00 | 1.00 | 1.00 | 1.00 | 1.000 | 1.00 |
| 4 | diff | 11.60 | 10.40 | 10.11 | 10.55 | 9.335 | 10.69 |
| 3 | apply+diff2 | 37.92 | 33.65 | 37.87 | 40.18 | 34.624 | 69.29 |
| 2 | apply+diff | 99.62 | 97.04 | 96.58 | 110.65 | 85.583 | 102.88 |
| 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.1759 | 0.231 | 0.2781 | 0.2421 | 0.3572 | 0.5039 |
| 4 | diff + t | 2.4645 | 2.641 | 2.9138 | 2.6841 | 3.2914 | 3.9265 |
| 3 | apply+diff2 | 7.3572 | 8.879 | 10.7272 | 9.4393 | 11.9757 | 27.1173 |
| 2 | apply+diff | 19.5868 | 21.590 | 26.3636 | 25.4653 | 29.2603 | 46.4524 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | rowDiffs | 1.00 | 1.00 | 1.00 | 1.00 | 1.000 | 1.000 |
| 4 | diff + t | 14.01 | 11.43 | 10.48 | 11.09 | 9.213 | 7.792 |
| 3 | apply+diff2 | 41.82 | 38.44 | 38.57 | 38.98 | 33.523 | 53.814 |
| 2 | apply+diff | 111.34 | 93.48 | 94.79 | 105.17 | 81.907 | 92.185 |
| 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 |
|---|---|---|---|---|---|---|
| colDiffs | 187.5 | 225 | 283.0 | 241.6 | 362.2 | 426.9 |
| rowDiffs | 175.9 | 231 | 278.1 | 242.1 | 357.2 | 503.9 |
| expr | min | lq | mean | median | uq | max |
|---|---|---|---|---|---|---|
| colDiffs | 1.0000 | 1.000 | 1.0000 | 1.000 | 1.0000 | 1.00 |
| rowDiffs | 0.9384 | 1.026 | 0.9826 | 1.002 | 0.9862 | 1.18 |
| Figure: Benchmarking of colDiffs() and rowDiffs() on integer+100x1000 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds. |

> X <- data[["1000x100"]]
> gc()
used (Mb) gc trigger (Mb) max used (Mb)
Ncells 651854 34.9 1168576 62.5 1168576 62.5
Vcells 12129470 92.6 35610798 271.7 68120027 519.8
> 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 651848 34.9 1168576 62.5 1168576 62.5
Vcells 12179513 93.0 35610798 271.7 68120027 519.8
> 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.1782 | 0.2227 | 0.2739 | 0.241 | 0.3459 | 0.4242 |
| 4 | diff | 1.8974 | 2.1779 | 2.4874 | 2.282 | 2.7595 | 4.1113 |
| 3 | apply+diff2 | 3.4973 | 3.5718 | 4.5654 | 4.277 | 5.1853 | 14.4731 |
| 2 | apply+diff | 6.4684 | 6.6347 | 8.1138 | 7.354 | 9.5434 | 15.5883 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | colDiffs | 1.00 | 1.00 | 1.000 | 1.000 | 1.000 | 1.000 |
| 4 | diff | 10.65 | 9.78 | 9.081 | 9.469 | 7.978 | 9.691 |
| 3 | apply+diff2 | 19.62 | 16.04 | 16.666 | 17.748 | 14.992 | 34.117 |
| 2 | apply+diff | 36.29 | 29.79 | 29.620 | 30.515 | 27.591 | 36.746 |
| 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.1882 | 0.2381 | 0.271 | 0.2443 | 0.2853 | 0.4196 |
| 4 | diff + t | 2.1904 | 2.2991 | 2.551 | 2.3282 | 2.4814 | 4.3404 |
| 3 | apply+diff2 | 3.5131 | 3.7225 | 4.753 | 4.4778 | 5.6942 | 11.3488 |
| 2 | apply+diff | 6.4980 | 6.7209 | 8.358 | 7.5251 | 9.7076 | 20.5862 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | rowDiffs | 1.00 | 1.000 | 1.000 | 1.000 | 1.000 | 1.00 |
| 4 | diff + t | 11.64 | 9.656 | 9.413 | 9.532 | 8.699 | 10.34 |
| 3 | apply+diff2 | 18.66 | 15.635 | 17.541 | 18.332 | 19.962 | 27.05 |
| 2 | apply+diff | 34.52 | 28.228 | 30.846 | 30.808 | 34.032 | 49.06 |
| 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 |
|---|---|---|---|---|---|---|
| colDiffs | 178.2 | 222.7 | 273.9 | 241.0 | 345.9 | 424.2 |
| rowDiffs | 188.2 | 238.1 | 271.0 | 244.3 | 285.3 | 419.6 |
| expr | min | lq | mean | median | uq | max |
|---|---|---|---|---|---|---|
| colDiffs | 1.000 | 1.000 | 1.0000 | 1.000 | 1.0000 | 1.0000 |
| rowDiffs | 1.056 | 1.069 | 0.9892 | 1.014 | 0.8247 | 0.9891 |
| Figure: Benchmarking of colDiffs() and rowDiffs() on integer+1000x100 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds. |

> rmatrix <- function(nrow, ncol, mode = c("logical", "double", "integer", "index"), range = c(-100,
+ +100), naProb = 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 (naProb > 0)
+ X[sample(n, size = naProb * 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)> X <- data[["10x10"]]
> gc()
used (Mb) gc trigger (Mb) max used (Mb)
Ncells 651900 34.9 1168576 62.5 1168576 62.5
Vcells 12245170 93.5 35610798 271.7 68120027 519.8
> 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 651885 34.9 1168576 62.5 1168576 62.5
Vcells 12245298 93.5 35610798 271.7 68120027 519.8
> 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.0027 | 0.0058 | 0.0081 | 0.0075 | 0.0094 | 0.0227 |
| 4 | diff | 0.0166 | 0.0244 | 0.0318 | 0.0320 | 0.0354 | 0.0885 |
| 3 | apply+diff2 | 0.0928 | 0.1440 | 0.1443 | 0.1492 | 0.1519 | 0.3434 |
| 2 | apply+diff | 0.1848 | 0.2874 | 0.2917 | 0.2933 | 0.2999 | 0.6637 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | colDiffs | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 |
| 4 | diff | 6.143 | 4.233 | 3.928 | 4.256 | 3.755 | 3.898 |
| 3 | apply+diff2 | 34.425 | 24.930 | 17.843 | 19.868 | 16.101 | 15.118 |
| 2 | apply+diff | 68.564 | 49.761 | 36.075 | 39.070 | 31.794 | 29.219 |
| 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.0023 | 0.0035 | 0.0057 | 0.0054 | 0.0062 | 0.0535 |
| 4 | diff + t | 0.0243 | 0.0285 | 0.0357 | 0.0341 | 0.0366 | 0.1259 |
| 3 | apply+diff2 | 0.0928 | 0.0974 | 0.1073 | 0.0993 | 0.1028 | 0.1794 |
| 2 | apply+diff | 0.1871 | 0.1950 | 0.2042 | 0.1973 | 0.2017 | 0.3314 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | rowDiffs | 1.00 | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 |
| 4 | diff + t | 10.50 | 8.221 | 6.264 | 6.321 | 5.936 | 2.353 |
| 3 | apply+diff2 | 40.16 | 28.108 | 18.805 | 18.427 | 16.683 | 3.353 |
| 2 | apply+diff | 80.99 | 56.271 | 35.794 | 36.603 | 32.741 | 6.194 |
| 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 | 2.310 | 3.465 | 5.706 | 5.390 | 6.161 | 53.51 |
| 1 | colDiffs | 2.695 | 5.775 | 8.085 | 7.508 | 9.432 | 22.71 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 2 | rowDiffs | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 | 1.0000 |
| 1 | colDiffs | 1.167 | 1.667 | 1.417 | 1.393 | 1.531 | 0.4245 |
| Figure: Benchmarking of colDiffs() and rowDiffs() on double+10x10 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds. |

> X <- data[["100x100"]]
> gc()
used (Mb) gc trigger (Mb) max used (Mb)
Ncells 651923 34.9 1168576 62.5 1168576 62.5
Vcells 12245964 93.5 35610798 271.7 68120027 519.8
> 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 651917 34.9 1168576 62.5 1168576 62.5
Vcells 12256007 93.6 35610798 271.7 68120027 519.8
> 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.0200 | 0.0335 | 0.0460 | 0.0464 | 0.0579 | 0.0758 |
| 4 | diff | 0.1424 | 0.2271 | 0.2707 | 0.2602 | 0.3422 | 0.3780 |
| 3 | apply+diff2 | 0.7507 | 1.2303 | 1.2811 | 1.3169 | 1.3774 | 3.8992 |
| 2 | apply+diff | 1.8920 | 2.1965 | 3.1496 | 3.1135 | 3.2292 | 16.7012 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | colDiffs | 1.000 | 1.000 | 1.000 | 1.00 | 1.000 | 1.000 |
| 4 | diff | 7.115 | 6.781 | 5.886 | 5.61 | 5.907 | 4.985 |
| 3 | apply+diff2 | 37.499 | 36.734 | 27.860 | 28.39 | 23.774 | 51.416 |
| 2 | apply+diff | 94.517 | 65.584 | 68.493 | 67.12 | 55.737 | 220.225 |
| 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.0192 | 0.0212 | 0.0361 | 0.0333 | 0.0516 | 0.0666 |
| 4 | diff + t | 0.1721 | 0.1807 | 0.2240 | 0.2281 | 0.2392 | 0.3630 |
| 3 | apply+diff2 | 0.7510 | 0.8300 | 1.0368 | 0.8819 | 0.9722 | 10.9681 |
| 2 | apply+diff | 1.8651 | 2.0175 | 2.2546 | 2.0730 | 2.1783 | 12.2207 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | rowDiffs | 1.00 | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 |
| 4 | diff + t | 8.94 | 8.536 | 6.197 | 6.849 | 4.638 | 5.451 |
| 3 | apply+diff2 | 39.02 | 39.197 | 28.681 | 26.485 | 18.847 | 164.691 |
| 2 | apply+diff | 96.90 | 95.284 | 62.372 | 62.252 | 42.227 | 183.500 |
| 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 | |
|---|---|---|---|---|---|---|---|
| 2 | rowDiffs | 19.25 | 21.17 | 36.15 | 33.30 | 51.58 | 66.60 |
| 1 | colDiffs | 20.02 | 33.49 | 45.98 | 46.39 | 57.94 | 75.84 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 2 | rowDiffs | 1.00 | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 |
| 1 | colDiffs | 1.04 | 1.582 | 1.272 | 1.393 | 1.123 | 1.139 |
| Figure: Benchmarking of colDiffs() and rowDiffs() on double+100x100 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds. |

> X <- data[["1000x10"]]
> gc()
used (Mb) gc trigger (Mb) max used (Mb)
Ncells 651949 34.9 1168576 62.5 1168576 62.5
Vcells 12246811 93.5 35610798 271.7 68120027 519.8
> 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 651952 34.9 1168576 62.5 1168576 62.5
Vcells 12256869 93.6 35610798 271.7 68120027 519.8
> 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.0208 | 0.0327 | 0.0384 | 0.0371 | 0.0431 | 0.0566 |
| 4 | diff | 0.1528 | 0.2433 | 0.2561 | 0.2587 | 0.2851 | 0.3288 |
| 3 | apply+diff2 | 0.3980 | 0.6361 | 0.6614 | 0.6812 | 0.7243 | 0.8931 |
| 2 | apply+diff | 0.6479 | 1.0375 | 1.0505 | 1.0800 | 1.1327 | 1.3077 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | colDiffs | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 |
| 4 | diff | 7.351 | 7.435 | 6.662 | 6.964 | 6.612 | 5.809 |
| 3 | apply+diff2 | 19.147 | 19.441 | 17.203 | 18.336 | 16.799 | 15.782 |
| 2 | apply+diff | 31.165 | 31.705 | 27.323 | 29.072 | 26.272 | 23.108 |
| 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.0192 | 0.0246 | 0.0310 | 0.0295 | 0.0366 | 0.0693 |
| 4 | diff + t | 0.1836 | 0.1952 | 0.2230 | 0.2140 | 0.2306 | 0.3646 |
| 3 | apply+diff2 | 0.3923 | 0.4244 | 0.4934 | 0.4806 | 0.5230 | 0.7499 |
| 2 | apply+diff | 0.6444 | 0.7064 | 0.7840 | 0.7470 | 0.8063 | 1.1091 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | rowDiffs | 1.000 | 1.000 | 1.00 | 1.000 | 1.000 | 1.000 |
| 4 | diff + t | 9.539 | 7.922 | 7.19 | 7.268 | 6.305 | 5.261 |
| 3 | apply+diff2 | 20.379 | 17.226 | 15.91 | 16.319 | 14.300 | 10.822 |
| 2 | apply+diff | 33.478 | 28.671 | 25.28 | 25.365 | 22.047 | 16.005 |
| 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 | |
|---|---|---|---|---|---|---|---|
| 2 | rowDiffs | 19.25 | 24.64 | 31.01 | 29.45 | 36.57 | 69.29 |
| 1 | colDiffs | 20.79 | 32.72 | 38.45 | 37.15 | 43.12 | 56.59 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 2 | rowDiffs | 1.00 | 1.000 | 1.00 | 1.000 | 1.000 | 1.0000 |
| 1 | colDiffs | 1.08 | 1.328 | 1.24 | 1.261 | 1.179 | 0.8167 |
| Figure: Benchmarking of colDiffs() and rowDiffs() on double+1000x10 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds. |

> X <- data[["10x1000"]]
> gc()
used (Mb) gc trigger (Mb) max used (Mb)
Ncells 652000 34.9 1168576 62.5 1168576 62.5
Vcells 12246856 93.5 35610798 271.7 68120027 519.8
> 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 651994 34.9 1168576 62.5 1168576 62.5
Vcells 12256899 93.6 35610798 271.7 68120027 519.8
> 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.0185 | 0.0339 | 0.0464 | 0.0508 | 0.0587 | 0.0720 |
| 4 | diff | 0.1582 | 0.2008 | 0.2332 | 0.2212 | 0.2724 | 0.4489 |
| 3 | apply+diff2 | 4.2965 | 4.6662 | 6.5428 | 6.9925 | 7.5439 | 22.4528 |
| 2 | apply+diff | 13.9034 | 15.0863 | 19.0904 | 17.8191 | 22.2090 | 31.2763 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | colDiffs | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 |
| 4 | diff | 8.562 | 5.926 | 5.023 | 4.352 | 4.639 | 6.235 |
| 3 | apply+diff2 | 232.506 | 137.740 | 140.917 | 137.608 | 128.503 | 311.901 |
| 2 | apply+diff | 752.388 | 445.327 | 411.164 | 350.670 | 378.305 | 434.472 |
| 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.0173 | 0.0296 | 0.0429 | 0.0448 | 0.0554 | 0.1105 |
| 4 | diff + t | 0.1913 | 0.2558 | 0.2801 | 0.2662 | 0.3160 | 0.4612 |
| 3 | apply+diff2 | 4.0817 | 4.5700 | 6.1980 | 5.9098 | 7.5210 | 14.2406 |
| 2 | apply+diff | 13.8279 | 14.8917 | 18.9992 | 18.0859 | 22.1860 | 34.2963 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | rowDiffs | 1.00 | 1.00 | 1.000 | 1.000 | 1.000 | 1.000 |
| 4 | diff + t | 11.04 | 8.63 | 6.529 | 5.936 | 5.701 | 4.174 |
| 3 | apply+diff2 | 235.61 | 154.17 | 144.461 | 131.773 | 135.674 | 128.894 |
| 2 | apply+diff | 798.19 | 502.38 | 442.829 | 403.267 | 400.221 | 310.422 |
| 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 | 17.32 | 29.64 | 42.90 | 44.85 | 55.43 | 110.48 |
| 1 | colDiffs | 18.48 | 33.88 | 46.43 | 50.81 | 58.71 | 71.99 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 2 | rowDiffs | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 | 1.0000 |
| 1 | colDiffs | 1.067 | 1.143 | 1.082 | 1.133 | 1.059 | 0.6516 |
| Figure: Benchmarking of colDiffs() and rowDiffs() on double+10x1000 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds. |

> X <- data[["100x1000"]]
> gc()
used (Mb) gc trigger (Mb) max used (Mb)
Ncells 652033 34.9 1168576 62.5 1168576 62.5
Vcells 12247891 93.5 35610798 271.7 68120027 519.8
> 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 652027 34.9 1168576 62.5 1168576 62.5
Vcells 12347934 94.3 35610798 271.7 68120027 519.8
> 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.1786 | 0.2847 | 0.3489 | 0.3638 | 0.3734 | 1.687 |
| 4 | diff | 2.1011 | 2.6652 | 3.1360 | 2.8827 | 3.6598 | 4.719 |
| 3 | apply+diff2 | 7.3934 | 8.6341 | 11.2506 | 10.9654 | 12.8413 | 25.931 |
| 2 | apply+diff | 19.0575 | 21.4077 | 27.4937 | 25.6127 | 31.6163 | 46.958 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | colDiffs | 1.00 | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 |
| 4 | diff | 11.76 | 9.362 | 8.989 | 7.924 | 9.801 | 2.798 |
| 3 | apply+diff2 | 41.39 | 30.330 | 32.249 | 30.143 | 34.390 | 15.376 |
| 2 | apply+diff | 106.69 | 75.201 | 78.810 | 70.407 | 84.670 | 27.844 |
| 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.1775 | 0.308 | 0.3305 | 0.357 | 0.3667 | 0.4785 |
| 4 | diff + t | 2.4933 | 2.723 | 3.0462 | 2.823 | 3.3662 | 4.6826 |
| 3 | apply+diff2 | 7.7537 | 10.111 | 12.1467 | 10.654 | 13.3417 | 32.7014 |
| 2 | apply+diff | 19.4848 | 22.295 | 26.9076 | 25.571 | 30.6418 | 46.9913 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | rowDiffs | 1.00 | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 |
| 4 | diff + t | 14.05 | 8.841 | 9.216 | 7.907 | 9.181 | 9.786 |
| 3 | apply+diff2 | 43.69 | 32.831 | 36.750 | 29.839 | 36.386 | 68.342 |
| 2 | apply+diff | 109.80 | 72.395 | 81.409 | 71.619 | 83.568 | 98.206 |
| 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 | 177.5 | 308.0 | 330.5 | 357.0 | 366.7 | 478.5 |
| 1 | colDiffs | 178.6 | 284.7 | 348.9 | 363.8 | 373.4 | 1686.5 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 2 | rowDiffs | 1.000 | 1.0000 | 1.000 | 1.000 | 1.000 | 1.000 |
| 1 | colDiffs | 1.006 | 0.9244 | 1.056 | 1.019 | 1.018 | 3.525 |
| Figure: Benchmarking of colDiffs() and rowDiffs() on double+100x1000 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds. |

> X <- data[["1000x100"]]
> gc()
used (Mb) gc trigger (Mb) max used (Mb)
Ncells 652068 34.9 1168576 62.5 1168576 62.5
Vcells 12247914 93.5 35610798 271.7 68120027 519.8
> 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 652062 34.9 1168576 62.5 1168576 62.5
Vcells 12347957 94.3 35610798 271.7 68120027 519.8
> 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.1786 | 0.2758 | 0.3995 | 0.3692 | 0.4458 | 0.8954 |
| 4 | diff | 1.5518 | 1.9740 | 2.8880 | 2.2114 | 3.5845 | 13.8699 |
| 3 | apply+diff2 | 3.6959 | 4.1153 | 5.4097 | 5.5884 | 6.2940 | 10.0434 |
| 2 | apply+diff | 6.3182 | 7.3878 | 9.4272 | 9.6958 | 10.8253 | 15.2954 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | colDiffs | 1.000 | 1.000 | 1.00 | 1.00 | 1.000 | 1.00 |
| 4 | diff | 8.687 | 7.157 | 7.23 | 5.99 | 8.041 | 15.49 |
| 3 | apply+diff2 | 20.692 | 14.920 | 13.54 | 15.14 | 14.119 | 11.22 |
| 2 | apply+diff | 35.373 | 26.785 | 23.60 | 26.26 | 24.284 | 17.08 |
| 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.1836 | 0.3374 | 0.4164 | 0.3674 | 0.3826 | 7.341 |
| 4 | diff + t | 1.9579 | 2.2749 | 2.9718 | 3.0140 | 3.4453 | 4.567 |
| 3 | apply+diff2 | 3.8268 | 5.8088 | 6.4758 | 6.3787 | 7.7231 | 11.845 |
| 2 | apply+diff | 6.5792 | 8.2859 | 9.8003 | 9.4483 | 10.7860 | 18.800 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | rowDiffs | 1.00 | 1.000 | 1.000 | 1.000 | 1.000 | 1.0000 |
| 4 | diff + t | 10.66 | 6.742 | 7.136 | 8.203 | 9.004 | 0.6221 |
| 3 | apply+diff2 | 20.84 | 17.216 | 15.551 | 17.360 | 20.184 | 1.6135 |
| 2 | apply+diff | 35.83 | 24.557 | 23.535 | 25.714 | 28.188 | 2.5608 |
| 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 | |
|---|---|---|---|---|---|---|---|
| 2 | rowDiffs | 183.6 | 337.4 | 416.4 | 367.4 | 382.6 | 7341.5 |
| 1 | colDiffs | 178.6 | 275.8 | 399.5 | 369.2 | 445.8 | 895.4 |
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 2 | rowDiffs | 1.0000 | 1.0000 | 1.0000 | 1.000 | 1.000 | 1.000 |
| 1 | colDiffs | 0.9727 | 0.8175 | 0.9593 | 1.005 | 1.165 | 0.122 |
| Figure: Benchmarking of colDiffs() and rowDiffs() on double+1000x100 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds. |

R Under development (unstable) (2015-02-27 r67909)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] markdown_0.7.7 microbenchmark_1.4-2 matrixStats_0.14.0-9000
[4] ggplot2_1.0.0 knitr_1.9.3 R.devices_2.13.0
[7] R.utils_2.0.0 R.oo_1.19.0 R.methodsS3_1.7.0
loaded via a namespace (and not attached):
[1] Rcpp_0.11.4 splines_3.2.0 MASS_7.3-39
[4] munsell_0.4.2 lattice_0.20-30 colorspace_1.2-4
[7] R.cache_0.11.1-9000 multcomp_1.3-9 stringr_0.6.2
[10] plyr_1.8.1 tools_3.2.0 grid_3.2.0
[13] gtable_0.1.2 TH.data_1.0-6 survival_2.38-1
[16] digest_0.6.8 R.rsp_0.20.0 reshape2_1.4.1
[19] formatR_1.0.3 base64enc_0.1-3 mime_0.2.1
[22] evaluate_0.5.7 labeling_0.3 sandwich_2.3-2
[25] scales_0.2.4 mvtnorm_1.0-2 zoo_1.7-12
[28] Cairo_1.5-6 proto_0.3-10 Total processing time was 1.25 mins.
To reproduce this report, do:
html <- matrixStats:::benchmark('colDiffs')Copyright Henrik Bengtsson. Last updated on 2015-03-02 17:02:54 (-0800 UTC). Powered by RSP.
<script> var link = document.createElement('link'); link.rel = 'icon'; link.href = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAADFBMVEX9/v0AAP/9/v3//wBEQjoBAAAABHRSTlP//wD//gy7CwAAAGJJREFUOI3N0rESwCAIA9Ag///PXdoiBk0HhmbNO49DMETQCexNCSyFgdlGoO5DYOr9ThLgPosA7osIQP0sHuDOog8UI/ALa988wzdwXJRctf4s+d36YPTJ6aMd8ux3+QO4ABTtB85yDAh9AAAAAElFTkSuQmCC" document.getElementsByTagName('head')[0].appendChild(link); </script>[Benchmark reports](Benchmark reports)