indexByRow - HenrikBengtsson/matrixStats GitHub Wiki
matrixStats: Benchmark report
This report benchmark the performance of indexByRow() against alternative methods:
- 
indexByRow_R1()based inmatrix(..., byrow = TRUE)
- 
indexByRow_R2()is a modified version ofindexByRow_R1()
where indexByRow_R1() and indexByRow_R2() are defined as in the Appendix.
> data <- rmatrices(mode = "index")where rmatrices() is defined in the Appendix.
> X <- data[["10x10"]]
> dim <- dim(X)
> idxsList <- list(`all-by-NULL` = NULL, all = seq_len(prod(dim)), odd = seq(from = 1, to = prod(dim), 
+     by = 2L))
> str(idxsList)
List of 3
 $ all-by-NULL: NULL
 $ all        : int [1:100] 1 2 3 4 5 6 7 8 9 10 ...
 $ odd        : num [1:50] 1 3 5 7 9 11 13 15 17 19 ...> stats <- microbenchmark(indexByRow = indexByRow(dim, idxs = idxs), indexByRow_R1 = indexByRow_R1(dim, 
+     idxs = idxs), indexByRow_R2 = indexByRow_R2(dim, idxs = idxs), unit = "ms")Table: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 10x10+all-by-NULL data. The top panel shows times in milliseconds and the bottom panel shows relative times.
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | indexByRow | 0.000709 | 0.0010065 | 0.0012170 | 0.0011370 | 0.0012295 | 0.007657 | 
| 3 | indexByRow_R2 | 0.003279 | 0.0040355 | 0.0042458 | 0.0042135 | 0.0043475 | 0.008286 | 
| 2 | indexByRow_R1 | 0.003485 | 0.0041495 | 0.0045250 | 0.0042590 | 0.0044180 | 0.029376 | 
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | indexByRow | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 
| 3 | indexByRow_R2 | 4.624824 | 4.009439 | 3.488792 | 3.705805 | 3.535990 | 1.082147 | 
| 2 | indexByRow_R1 | 4.915374 | 4.122702 | 3.718196 | 3.745822 | 3.593331 | 3.836489 | 
Figure: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 10x10+all-by-NULL data. Outliers are displayed as crosses. Times are in milliseconds.

> stats <- microbenchmark(indexByRow = indexByRow(dim, idxs = idxs), indexByRow_R1 = indexByRow_R1(dim, 
+     idxs = idxs), indexByRow_R2 = indexByRow_R2(dim, idxs = idxs), unit = "ms")Table: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 10x10+all data. The top panel shows times in milliseconds and the bottom panel shows relative times.
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | indexByRow | 0.001452 | 0.0017125 | 0.0018830 | 0.0018285 | 0.0018880 | 0.007985 | 
| 2 | indexByRow_R1 | 0.003937 | 0.0044535 | 0.0048252 | 0.0046515 | 0.0049195 | 0.018117 | 
| 3 | indexByRow_R2 | 0.004492 | 0.0051310 | 0.0054952 | 0.0052820 | 0.0054460 | 0.024536 | 
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | indexByRow | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 
| 2 | indexByRow_R1 | 2.711432 | 2.600584 | 2.562457 | 2.543888 | 2.605667 | 2.268879 | 
| 3 | indexByRow_R2 | 3.093664 | 2.996204 | 2.918276 | 2.888707 | 2.884534 | 3.072761 | 
Figure: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 10x10+all data. Outliers are displayed as crosses. Times are in milliseconds.

> stats <- microbenchmark(indexByRow = indexByRow(dim, idxs = idxs), indexByRow_R1 = indexByRow_R1(dim, 
+     idxs = idxs), indexByRow_R2 = indexByRow_R2(dim, idxs = idxs), unit = "ms")Table: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 10x10+odd data. The top panel shows times in milliseconds and the bottom panel shows relative times.
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | indexByRow | 0.001163 | 0.0014535 | 0.0016794 | 0.0015955 | 0.0017375 | 0.008264 | 
| 3 | indexByRow_R2 | 0.003142 | 0.0038215 | 0.0040446 | 0.0039855 | 0.0041055 | 0.011395 | 
| 2 | indexByRow_R1 | 0.004041 | 0.0044965 | 0.0049489 | 0.0047125 | 0.0048525 | 0.024988 | 
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | indexByRow | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 
| 3 | indexByRow_R2 | 2.701634 | 2.629171 | 2.408373 | 2.497963 | 2.362878 | 1.378872 | 
| 2 | indexByRow_R1 | 3.474635 | 3.093567 | 2.946891 | 2.953620 | 2.792806 | 3.023717 | 
Figure: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 10x10+odd data. Outliers are displayed as crosses. Times are in milliseconds.

> X <- data[["100x100"]]
> dim <- dim(X)
> idxsList <- list(`all-by-NULL` = NULL, all = seq_len(prod(dim)), odd = seq(from = 1, to = prod(dim), 
+     by = 2L))
> str(idxsList)
List of 3
 $ all-by-NULL: NULL
 $ all        : int [1:10000] 1 2 3 4 5 6 7 8 9 10 ...
 $ odd        : num [1:5000] 1 3 5 7 9 11 13 15 17 19 ...> stats <- microbenchmark(indexByRow = indexByRow(dim, idxs = idxs), indexByRow_R1 = indexByRow_R1(dim, 
+     idxs = idxs), indexByRow_R2 = indexByRow_R2(dim, idxs = idxs), unit = "ms")Table: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 100x100+all-by-NULL data. The top panel shows times in milliseconds and the bottom panel shows relative times.
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | indexByRow | 0.010584 | 0.0110635 | 0.0116042 | 0.0112615 | 0.0113900 | 0.027467 | 
| 3 | indexByRow_R2 | 0.047659 | 0.0488760 | 0.0501652 | 0.0496225 | 0.0502945 | 0.066203 | 
| 2 | indexByRow_R1 | 0.047369 | 0.0489060 | 0.0500027 | 0.0498425 | 0.0504045 | 0.056429 | 
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | indexByRow | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 
| 3 | indexByRow_R2 | 4.502929 | 4.417770 | 4.323043 | 4.406385 | 4.415672 | 2.410274 | 
| 2 | indexByRow_R1 | 4.475529 | 4.420482 | 4.309035 | 4.425920 | 4.425329 | 2.054429 | 
Figure: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 100x100+all-by-NULL data. Outliers are displayed as crosses. Times are in milliseconds.

> stats <- microbenchmark(indexByRow = indexByRow(dim, idxs = idxs), indexByRow_R1 = indexByRow_R1(dim, 
+     idxs = idxs), indexByRow_R2 = indexByRow_R2(dim, idxs = idxs), unit = "ms")Table: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 100x100+all data. The top panel shows times in milliseconds and the bottom panel shows relative times.
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 2 | indexByRow_R1 | 0.061580 | 0.062828 | 0.0645130 | 0.0632865 | 0.0647365 | 0.105998 | 
| 1 | indexByRow | 0.071489 | 0.071980 | 0.0729375 | 0.0722700 | 0.0725520 | 0.119306 | 
| 3 | indexByRow_R2 | 0.234603 | 0.235628 | 0.2374760 | 0.2365255 | 0.2379765 | 0.254684 | 
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 2 | indexByRow_R1 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 
| 1 | indexByRow | 1.160913 | 1.145668 | 1.130586 | 1.141950 | 1.120728 | 1.125549 | 
| 3 | indexByRow_R2 | 3.809727 | 3.750366 | 3.681054 | 3.737377 | 3.676079 | 2.402725 | 
Figure: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 100x100+all data. Outliers are displayed as crosses. Times are in milliseconds.

> stats <- microbenchmark(indexByRow = indexByRow(dim, idxs = idxs), indexByRow_R1 = indexByRow_R1(dim, 
+     idxs = idxs), indexByRow_R2 = indexByRow_R2(dim, idxs = idxs), unit = "ms")Table: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 100x100+odd data. The top panel shows times in milliseconds and the bottom panel shows relative times.
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | indexByRow | 0.042664 | 0.043018 | 0.0440147 | 0.0433035 | 0.0442365 | 0.063995 | 
| 2 | indexByRow_R1 | 0.064634 | 0.065214 | 0.0665457 | 0.0660045 | 0.0667575 | 0.091848 | 
| 3 | indexByRow_R2 | 0.115175 | 0.115985 | 0.1187264 | 0.1175920 | 0.1185565 | 0.156242 | 
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | indexByRow | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 
| 2 | indexByRow_R1 | 1.514954 | 1.515970 | 1.511895 | 1.524230 | 1.509105 | 1.435237 | 
| 3 | indexByRow_R2 | 2.699583 | 2.696197 | 2.697424 | 2.715531 | 2.680061 | 2.441472 | 
Figure: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 100x100+odd data. Outliers are displayed as crosses. Times are in milliseconds.

> X <- data[["1000x10"]]
> dim <- dim(X)
> idxsList <- list(`all-by-NULL` = NULL, all = seq_len(prod(dim)), odd = seq(from = 1, to = prod(dim), 
+     by = 2L))
> str(idxsList)
List of 3
 $ all-by-NULL: NULL
 $ all        : int [1:10000] 1 2 3 4 5 6 7 8 9 10 ...
 $ odd        : num [1:5000] 1 3 5 7 9 11 13 15 17 19 ...> stats <- microbenchmark(indexByRow = indexByRow(dim, idxs = idxs), indexByRow_R1 = indexByRow_R1(dim, 
+     idxs = idxs), indexByRow_R2 = indexByRow_R2(dim, idxs = idxs), unit = "ms")Table: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 1000x10+all-by-NULL data. The top panel shows times in milliseconds and the bottom panel shows relative times.
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | indexByRow | 0.009846 | 0.0102395 | 0.0105808 | 0.0104415 | 0.0105890 | 0.018708 | 
| 3 | indexByRow_R2 | 0.047214 | 0.0484210 | 0.0501052 | 0.0491350 | 0.0499515 | 0.089051 | 
| 2 | indexByRow_R1 | 0.047224 | 0.0484810 | 0.0497814 | 0.0491665 | 0.0499275 | 0.064060 | 
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | indexByRow | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 
| 3 | indexByRow_R2 | 4.795247 | 4.728844 | 4.735507 | 4.705742 | 4.717301 | 4.760049 | 
| 2 | indexByRow_R1 | 4.796262 | 4.734704 | 4.704903 | 4.708758 | 4.715034 | 3.424203 | 
Figure: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 1000x10+all-by-NULL data. Outliers are displayed as crosses. Times are in milliseconds.

> stats <- microbenchmark(indexByRow = indexByRow(dim, idxs = idxs), indexByRow_R1 = indexByRow_R1(dim, 
+     idxs = idxs), indexByRow_R2 = indexByRow_R2(dim, idxs = idxs), unit = "ms")Table: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 1000x10+all data. The top panel shows times in milliseconds and the bottom panel shows relative times.
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 2 | indexByRow_R1 | 0.061297 | 0.0621330 | 0.0633183 | 0.0627155 | 0.0637360 | 0.076457 | 
| 1 | indexByRow | 0.071533 | 0.0720700 | 0.0726449 | 0.0722510 | 0.0725785 | 0.094779 | 
| 3 | indexByRow_R2 | 0.234260 | 0.2354485 | 0.2375439 | 0.2362900 | 0.2386405 | 0.257215 | 
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 2 | indexByRow_R1 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 
| 1 | indexByRow | 1.166990 | 1.159931 | 1.147297 | 1.152044 | 1.138736 | 1.239638 | 
| 3 | indexByRow_R2 | 3.821721 | 3.789427 | 3.751585 | 3.767649 | 3.744203 | 3.364179 | 
Figure: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 1000x10+all data. Outliers are displayed as crosses. Times are in milliseconds.

> stats <- microbenchmark(indexByRow = indexByRow(dim, idxs = idxs), indexByRow_R1 = indexByRow_R1(dim, 
+     idxs = idxs), indexByRow_R2 = indexByRow_R2(dim, idxs = idxs), unit = "ms")Table: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 1000x10+odd data. The top panel shows times in milliseconds and the bottom panel shows relative times.
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | indexByRow | 0.043567 | 0.0440405 | 0.0444613 | 0.0442165 | 0.0444835 | 0.050173 | 
| 2 | indexByRow_R1 | 0.065186 | 0.0659265 | 0.0670409 | 0.0663105 | 0.0670705 | 0.089506 | 
| 3 | indexByRow_R2 | 0.117182 | 0.1182080 | 0.1191417 | 0.1185680 | 0.1192195 | 0.129929 | 
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | indexByRow | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 
| 2 | indexByRow_R1 | 1.496224 | 1.496952 | 1.507849 | 1.499678 | 1.507761 | 1.783948 | 
| 3 | indexByRow_R2 | 2.689696 | 2.684075 | 2.679674 | 2.681533 | 2.680084 | 2.589620 | 
Figure: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 1000x10+odd data. Outliers are displayed as crosses. Times are in milliseconds.

> X <- data[["10x1000"]]
> dim <- dim(X)
> idxsList <- list(`all-by-NULL` = NULL, all = seq_len(prod(dim)), odd = seq(from = 1, to = prod(dim), 
+     by = 2L))
> str(idxsList)
List of 3
 $ all-by-NULL: NULL
 $ all        : int [1:10000] 1 2 3 4 5 6 7 8 9 10 ...
 $ odd        : num [1:5000] 1 3 5 7 9 11 13 15 17 19 ...> stats <- microbenchmark(indexByRow = indexByRow(dim, idxs = idxs), indexByRow_R1 = indexByRow_R1(dim, 
+     idxs = idxs), indexByRow_R2 = indexByRow_R2(dim, idxs = idxs), unit = "ms")Table: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 10x1000+all-by-NULL data. The top panel shows times in milliseconds and the bottom panel shows relative times.
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | indexByRow | 0.009583 | 0.0103150 | 0.0108005 | 0.0105130 | 0.0107850 | 0.018775 | 
| 3 | indexByRow_R2 | 0.045863 | 0.0475715 | 0.0483974 | 0.0482065 | 0.0488985 | 0.056372 | 
| 2 | indexByRow_R1 | 0.046520 | 0.0475940 | 0.0489322 | 0.0482775 | 0.0496545 | 0.066893 | 
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | indexByRow | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 
| 3 | indexByRow_R2 | 4.785871 | 4.611876 | 4.481030 | 4.585418 | 4.533936 | 3.002503 | 
| 2 | indexByRow_R1 | 4.854430 | 4.614057 | 4.530548 | 4.592172 | 4.604033 | 3.562876 | 
Figure: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 10x1000+all-by-NULL data. Outliers are displayed as crosses. Times are in milliseconds.

> stats <- microbenchmark(indexByRow = indexByRow(dim, idxs = idxs), indexByRow_R1 = indexByRow_R1(dim, 
+     idxs = idxs), indexByRow_R2 = indexByRow_R2(dim, idxs = idxs), unit = "ms")Table: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 10x1000+all data. The top panel shows times in milliseconds and the bottom panel shows relative times.
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 2 | indexByRow_R1 | 0.060350 | 0.0613125 | 0.0625899 | 0.0618195 | 0.0629455 | 0.075802 | 
| 1 | indexByRow | 0.071480 | 0.0719345 | 0.0723251 | 0.0721445 | 0.0724540 | 0.078394 | 
| 3 | indexByRow_R2 | 0.234345 | 0.2356565 | 0.2372685 | 0.2362250 | 0.2374815 | 0.261667 | 
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 2 | indexByRow_R1 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 
| 1 | indexByRow | 1.184424 | 1.173244 | 1.155539 | 1.167018 | 1.151059 | 1.034194 | 
| 3 | indexByRow_R2 | 3.883099 | 3.843531 | 3.790842 | 3.821205 | 3.772811 | 3.451980 | 
Figure: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 10x1000+all data. Outliers are displayed as crosses. Times are in milliseconds.

> stats <- microbenchmark(indexByRow = indexByRow(dim, idxs = idxs), indexByRow_R1 = indexByRow_R1(dim, 
+     idxs = idxs), indexByRow_R2 = indexByRow_R2(dim, idxs = idxs), unit = "ms")Table: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 10x1000+odd data. The top panel shows times in milliseconds and the bottom panel shows relative times.
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | indexByRow | 0.043739 | 0.0440865 | 0.0446986 | 0.0442500 | 0.0445840 | 0.058771 | 
| 2 | indexByRow_R1 | 0.064322 | 0.0653020 | 0.0666407 | 0.0656860 | 0.0665260 | 0.087385 | 
| 3 | indexByRow_R2 | 0.117426 | 0.1183710 | 0.1192118 | 0.1187655 | 0.1192815 | 0.128526 | 
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | indexByRow | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 
| 2 | indexByRow_R1 | 1.470587 | 1.481224 | 1.490892 | 1.484429 | 1.492150 | 1.486873 | 
| 3 | indexByRow_R2 | 2.684698 | 2.684972 | 2.667016 | 2.683966 | 2.675433 | 2.186895 | 
Figure: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 10x1000+odd data. Outliers are displayed as crosses. Times are in milliseconds.

> X <- data[["100x1000"]]
> dim <- dim(X)
> idxsList <- list(`all-by-NULL` = NULL, all = seq_len(prod(dim)), odd = seq(from = 1, to = prod(dim), 
+     by = 2L))
> str(idxsList)
List of 3
 $ all-by-NULL: NULL
 $ all        : int [1:100000] 1 2 3 4 5 6 7 8 9 10 ...
 $ odd        : num [1:50000] 1 3 5 7 9 11 13 15 17 19 ...> stats <- microbenchmark(indexByRow = indexByRow(dim, idxs = idxs), indexByRow_R1 = indexByRow_R1(dim, 
+     idxs = idxs), indexByRow_R2 = indexByRow_R2(dim, idxs = idxs), unit = "ms")Table: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 100x1000+all-by-NULL data. The top panel shows times in milliseconds and the bottom panel shows relative times.
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | indexByRow | 0.091331 | 0.1919825 | 0.2819083 | 0.1982920 | 0.2027125 | 10.455428 | 
| 3 | indexByRow_R2 | 0.450214 | 0.5536825 | 0.6677908 | 0.7247140 | 0.7388300 | 0.838227 | 
| 2 | indexByRow_R1 | 0.442711 | 0.5391645 | 0.6701900 | 0.7270285 | 0.7429530 | 0.838459 | 
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | indexByRow | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.0000000 | 
| 3 | indexByRow_R2 | 4.929476 | 2.884026 | 2.368822 | 3.654782 | 3.644719 | 0.0801715 | 
| 2 | indexByRow_R1 | 4.847325 | 2.808404 | 2.377333 | 3.666454 | 3.665058 | 0.0801937 | 
Figure: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 100x1000+all-by-NULL data. Outliers are displayed as crosses. Times are in milliseconds.

> stats <- microbenchmark(indexByRow = indexByRow(dim, idxs = idxs), indexByRow_R1 = indexByRow_R1(dim, 
+     idxs = idxs), indexByRow_R2 = indexByRow_R2(dim, idxs = idxs), unit = "ms")Table: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 100x1000+all data. The top panel shows times in milliseconds and the bottom panel shows relative times.
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 2 | indexByRow_R1 | 0.557787 | 0.5839215 | 0.6610249 | 0.5886285 | 0.6039455 | 6.304085 | 
| 1 | indexByRow | 0.691175 | 0.7073965 | 0.7255854 | 0.7106190 | 0.7264970 | 0.867763 | 
| 3 | indexByRow_R2 | 2.297614 | 2.3664470 | 2.5600072 | 2.3759905 | 2.4476710 | 8.512826 | 
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 2 | indexByRow_R1 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.0000000 | 
| 1 | indexByRow | 1.239138 | 1.211458 | 1.097667 | 1.207245 | 1.202918 | 0.1376509 | 
| 3 | indexByRow_R2 | 4.119160 | 4.052680 | 3.872785 | 4.036486 | 4.052801 | 1.3503666 | 
Figure: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 100x1000+all data. Outliers are displayed as crosses. Times are in milliseconds.

> stats <- microbenchmark(indexByRow = indexByRow(dim, idxs = idxs), indexByRow_R1 = indexByRow_R1(dim, 
+     idxs = idxs), indexByRow_R2 = indexByRow_R2(dim, idxs = idxs), unit = "ms")Table: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 100x1000+odd data. The top panel shows times in milliseconds and the bottom panel shows relative times.
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | indexByRow | 0.423800 | 0.4359650 | 0.4523315 | 0.447579 | 0.4616150 | 0.538598 | 
| 2 | indexByRow_R1 | 0.619296 | 0.6462575 | 0.7250991 | 0.660268 | 0.6745105 | 6.653620 | 
| 3 | indexByRow_R2 | 1.158735 | 1.1997540 | 1.2934724 | 1.230587 | 1.2622150 | 6.706267 | 
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | indexByRow | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.00000 | 
| 2 | indexByRow_R1 | 1.461293 | 1.482361 | 1.603026 | 1.475199 | 1.461197 | 12.35359 | 
| 3 | indexByRow_R2 | 2.734155 | 2.751950 | 2.859567 | 2.749430 | 2.734346 | 12.45134 | 
Figure: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 100x1000+odd data. Outliers are displayed as crosses. Times are in milliseconds.

> X <- data[["1000x100"]]
> dim <- dim(X)
> idxsList <- list(`all-by-NULL` = NULL, all = seq_len(prod(dim)), odd = seq(from = 1, to = prod(dim), 
+     by = 2L))
> str(idxsList)
List of 3
 $ all-by-NULL: NULL
 $ all        : int [1:100000] 1 2 3 4 5 6 7 8 9 10 ...
 $ odd        : num [1:50000] 1 3 5 7 9 11 13 15 17 19 ...> stats <- microbenchmark(indexByRow = indexByRow(dim, idxs = idxs), indexByRow_R1 = indexByRow_R1(dim, 
+     idxs = idxs), indexByRow_R2 = indexByRow_R2(dim, idxs = idxs), unit = "ms")Table: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 1000x100+all-by-NULL data. The top panel shows times in milliseconds and the bottom panel shows relative times.
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | indexByRow | 0.092339 | 0.1024225 | 0.1498238 | 0.117675 | 0.2091405 | 0.240272 | 
| 2 | indexByRow_R1 | 0.449351 | 0.4937740 | 0.7193290 | 0.559641 | 0.7779595 | 11.355862 | 
| 3 | indexByRow_R2 | 0.448114 | 0.4922105 | 0.6318389 | 0.586922 | 0.7845540 | 0.827782 | 
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | indexByRow | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 
| 2 | indexByRow_R1 | 4.866319 | 4.820952 | 4.801167 | 4.755819 | 3.719794 | 47.262527 | 
| 3 | indexByRow_R2 | 4.852922 | 4.805687 | 4.217214 | 4.987652 | 3.751325 | 3.445187 | 
Figure: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 1000x100+all-by-NULL data. Outliers are displayed as crosses. Times are in milliseconds.

> stats <- microbenchmark(indexByRow = indexByRow(dim, idxs = idxs), indexByRow_R1 = indexByRow_R1(dim, 
+     idxs = idxs), indexByRow_R2 = indexByRow_R2(dim, idxs = idxs), unit = "ms")Table: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 1000x100+all data. The top panel shows times in milliseconds and the bottom panel shows relative times.
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 2 | indexByRow_R1 | 0.597619 | 0.6173045 | 0.7003441 | 0.6327730 | 0.652469 | 6.435247 | 
| 1 | indexByRow | 0.706675 | 0.7189410 | 0.7483689 | 0.7444395 | 0.755921 | 0.901611 | 
| 3 | indexByRow_R2 | 2.336351 | 2.4240690 | 2.6136927 | 2.4901240 | 2.536624 | 8.559633 | 
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 2 | indexByRow_R1 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.0000000 | 
| 1 | indexByRow | 1.182484 | 1.164646 | 1.068573 | 1.176472 | 1.158555 | 0.1401051 | 
| 3 | indexByRow_R2 | 3.909432 | 3.926861 | 3.732012 | 3.935256 | 3.887730 | 1.3301172 | 
Figure: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 1000x100+all data. Outliers are displayed as crosses. Times are in milliseconds.

> stats <- microbenchmark(indexByRow = indexByRow(dim, idxs = idxs), indexByRow_R1 = indexByRow_R1(dim, 
+     idxs = idxs), indexByRow_R2 = indexByRow_R2(dim, idxs = idxs), unit = "ms")Table: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 1000x100+odd data. The top panel shows times in milliseconds and the bottom panel shows relative times.
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | indexByRow | 0.415424 | 0.4355645 | 0.5153917 | 0.457482 | 0.4709800 | 6.292663 | 
| 2 | indexByRow_R1 | 0.630225 | 0.6697285 | 0.6923113 | 0.686587 | 0.7110825 | 0.801584 | 
| 3 | indexByRow_R2 | 1.161292 | 1.2035270 | 1.3017618 | 1.241457 | 1.2711150 | 7.175120 | 
| expr | min | lq | mean | median | uq | max | |
|---|---|---|---|---|---|---|---|
| 1 | indexByRow | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.0000000 | 
| 2 | indexByRow_R1 | 1.517065 | 1.537610 | 1.343272 | 1.500796 | 1.509793 | 0.1273839 | 
| 3 | indexByRow_R2 | 2.795438 | 2.763143 | 2.525772 | 2.713674 | 2.698873 | 1.1402359 | 
Figure: Benchmarking of indexByRow(), indexByRow_R1() and indexByRow_R2() on 1000x100+odd data. Outliers are displayed as crosses. Times are in milliseconds.

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 17.71 secs.
To reproduce this report, do:
html <- matrixStats:::benchmark('indexByRow')Copyright Henrik Bengtsson. Last updated on 2019-09-10 20:58:15 (-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>> indexByRow_R1 <- function(dim, idxs = NULL, ...) {
+     n <- prod(dim)
+     x <- matrix(seq_len(n), nrow = dim[2L], ncol = dim[1L], byrow = TRUE)
+     if (!is.null(idxs)) 
+         x <- x[idxs]
+     as.vector(x)
+ }> indexByRow_R2 <- function(dim, idxs = NULL, ...) {
+     n <- prod(dim)
+     if (is.null(idxs)) {
+         x <- matrix(seq_len(n), nrow = dim[2L], ncol = dim[1L], byrow = TRUE)
+         as.vector(x)
+     }     else {
+         idxs <- idxs - 1
+         cols <- idxs%/%dim[2L]
+         rows <- idxs%%dim[2L]
+         cols + dim[1L] * rows + 1L
+     }
+ }> 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
+ }