-
Notifications
You must be signed in to change notification settings - Fork 34
weightedMedian_subset
matrixStats: Benchmark report
This report benchmark the performance of weightedMedian() on subsetted computation.
> rvector <- function(n, mode = c("logical", "double", "integer"), range = c(-100, +100), na_prob = 0) {
+ mode <- match.arg(mode)
+ if (mode == "logical") {
+ x <- sample(c(FALSE, TRUE), size = n, replace = TRUE)
+ } 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
+ x
+ }
> rvectors <- function(scale = 10, seed = 1, ...) {
+ set.seed(seed)
+ data <- list()
+ data[[1]] <- rvector(n = scale * 100, ...)
+ data[[2]] <- rvector(n = scale * 1000, ...)
+ data[[3]] <- rvector(n = scale * 10000, ...)
+ data[[4]] <- rvector(n = scale * 1e+05, ...)
+ data[[5]] <- rvector(n = scale * 1e+06, ...)
+ names(data) <- sprintf("n = %d", sapply(data, FUN = length))
+ data
+ }
> data <- rvectors(mode = "double")
> data <- data[1:3]
> x <- data[["n = 1000"]]
> idxs <- sample.int(length(x), size = length(x) * 0.7)
> x_S <- x[idxs]
> w <- runif(length(x))
> w_S <- x[idxs]
> gc()
used (Mb) gc trigger (Mb) max used (Mb)
Ncells 3255851 173.9 5709258 305.0 5709258 305.0
Vcells 8496062 64.9 26329732 200.9 87357391 666.5
> stats <- microbenchmark(weightedMedian_x_w_S = weightedMedian(x_S, w = w_S, ties = "mean", na.rm = FALSE),
+ `weightedMedian(x, w, idxs)` = weightedMedian(x, w = w, idxs = idxs, ties = "mean", na.rm = FALSE),
+ `weightedMedian(x[idxs], w[idxs])` = weightedMedian(x[idxs], w = w[idxs], ties = "mean", na.rm = FALSE),
+ unit = "ms")
Table: Benchmarking of weightedMedian_x_w_S(), weightedMedian(x, w, idxs)() and weightedMedian(x[idxs], w[idxs])() on n = 1000 data. The top panel shows times in milliseconds and the bottom panel shows relative times.
expr | min | lq | mean | median | uq | max | |
---|---|---|---|---|---|---|---|
1 | weightedMedian_x_w_S | 0.010414 | 0.0130905 | 0.0143459 | 0.0141285 | 0.0151400 | 0.031877 |
2 | weightedMedian(x, w, idxs) | 0.022567 | 0.0236415 | 0.0251023 | 0.0245135 | 0.0252615 | 0.074429 |
3 | weightedMedian(x[idxs], w[idxs]) | 0.025488 | 0.0267170 | 0.0276726 | 0.0274235 | 0.0283110 | 0.040621 |
expr | min | lq | mean | median | uq | max | |
---|---|---|---|---|---|---|---|
1 | weightedMedian_x_w_S | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 |
2 | weightedMedian(x, w, idxs) | 2.166987 | 1.806004 | 1.749792 | 1.735039 | 1.668527 | 2.334881 |
3 | weightedMedian(x[idxs], w[idxs]) | 2.447475 | 2.040946 | 1.928953 | 1.941006 | 1.869947 | 1.274304 |
Figure: Benchmarking of weightedMedian_x_w_S(), weightedMedian(x, w, idxs)() and weightedMedian(x[idxs], w[idxs])() on n = 1000 data. Outliers are displayed as crosses. Times are in milliseconds.
> x <- data[["n = 10000"]]
> idxs <- sample.int(length(x), size = length(x) * 0.7)
> x_S <- x[idxs]
> w <- runif(length(x))
> w_S <- x[idxs]
> gc()
used (Mb) gc trigger (Mb) max used (Mb)
Ncells 3252134 173.7 5709258 305.0 5709258 305.0
Vcells 6380837 48.7 26329732 200.9 87357391 666.5
> stats <- microbenchmark(weightedMedian_x_w_S = weightedMedian(x_S, w = w_S, ties = "mean", na.rm = FALSE),
+ `weightedMedian(x, w, idxs)` = weightedMedian(x, w = w, idxs = idxs, ties = "mean", na.rm = FALSE),
+ `weightedMedian(x[idxs], w[idxs])` = weightedMedian(x[idxs], w = w[idxs], ties = "mean", na.rm = FALSE),
+ unit = "ms")
Table: Benchmarking of weightedMedian_x_w_S(), weightedMedian(x, w, idxs)() and weightedMedian(x[idxs], w[idxs])() on n = 10000 data. The top panel shows times in milliseconds and the bottom panel shows relative times.
expr | min | lq | mean | median | uq | max | |
---|---|---|---|---|---|---|---|
1 | weightedMedian_x_w_S | 0.231744 | 0.2516715 | 0.2588082 | 0.2540240 | 0.2592365 | 0.396629 |
2 | weightedMedian(x, w, idxs) | 0.385316 | 0.4170595 | 0.4258152 | 0.4213790 | 0.4324240 | 0.553816 |
3 | weightedMedian(x[idxs], w[idxs]) | 0.403368 | 0.4368740 | 0.4446994 | 0.4409825 | 0.4498950 | 0.569672 |
expr | min | lq | mean | median | uq | max | |
---|---|---|---|---|---|---|---|
1 | weightedMedian_x_w_S | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 |
2 | weightedMedian(x, w, idxs) | 1.662680 | 1.657158 | 1.645292 | 1.658816 | 1.668068 | 1.396307 |
3 | weightedMedian(x[idxs], w[idxs]) | 1.740576 | 1.735890 | 1.718258 | 1.735988 | 1.735462 | 1.436284 |
Figure: Benchmarking of weightedMedian_x_w_S(), weightedMedian(x, w, idxs)() and weightedMedian(x[idxs], w[idxs])() on n = 10000 data. Outliers are displayed as crosses. Times are in milliseconds.
> x <- data[["n = 100000"]]
> idxs <- sample.int(length(x), size = length(x) * 0.7)
> x_S <- x[idxs]
> w <- runif(length(x))
> w_S <- x[idxs]
> gc()
used (Mb) gc trigger (Mb) max used (Mb)
Ncells 3252206 173.7 5709258 305.0 5709258 305.0
Vcells 6628897 50.6 26329732 200.9 87357391 666.5
> stats <- microbenchmark(weightedMedian_x_w_S = weightedMedian(x_S, w = w_S, ties = "mean", na.rm = FALSE),
+ `weightedMedian(x, w, idxs)` = weightedMedian(x, w = w, idxs = idxs, ties = "mean", na.rm = FALSE),
+ `weightedMedian(x[idxs], w[idxs])` = weightedMedian(x[idxs], w = w[idxs], ties = "mean", na.rm = FALSE),
+ unit = "ms")
Table: Benchmarking of weightedMedian_x_w_S(), weightedMedian(x, w, idxs)() and weightedMedian(x[idxs], w[idxs])() on n = 100000 data. The top panel shows times in milliseconds and the bottom panel shows relative times.
expr | min | lq | mean | median | uq | max | |
---|---|---|---|---|---|---|---|
1 | weightedMedian_x_w_S | 2.766280 | 2.850384 | 2.932332 | 2.910960 | 2.933612 | 3.840763 |
2 | weightedMedian(x, w, idxs) | 4.842974 | 5.154176 | 5.278415 | 5.216598 | 5.319541 | 6.688871 |
3 | weightedMedian(x[idxs], w[idxs]) | 4.938467 | 5.370499 | 5.581329 | 5.567918 | 5.653962 | 7.636192 |
expr | min | lq | mean | median | uq | max | |
---|---|---|---|---|---|---|---|
1 | weightedMedian_x_w_S | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 | 1.000000 |
2 | weightedMedian(x, w, idxs) | 1.750717 | 1.808239 | 1.800074 | 1.792054 | 1.813308 | 1.741547 |
3 | weightedMedian(x[idxs], w[idxs]) | 1.785238 | 1.884132 | 1.903376 | 1.912743 | 1.927304 | 1.988197 |
Figure: Benchmarking of weightedMedian_x_w_S(), weightedMedian(x, w, idxs)() and weightedMedian(x[idxs], w[idxs])() on n = 100000 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 4.63 secs.
To reproduce this report, do:
html <- matrixStats:::benchmark('weightedMedian_subset')
Copyright Dongcan Jiang. Last updated on 2019-09-10 21:14:50 (-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>