Last active
April 15, 2022 15:17
-
-
Save jmbarbone/83ee88f8c36b484656449cc77379504a to your computer and use it in GitHub Desktop.
ranking stuff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rank_limited <- function(x, method = c("auto", "shell", "quick", "radix")) { | |
u <- sort(unique(x), method = method) | |
match(x, u) | |
} | |
rank_limited2 <- function(x, method = c("auto", "shell", "quick", "radix")) { | |
u <- unique(sort(x, method = method)) | |
match(x, u) | |
} | |
x <- round(runif(1e4), 4) | |
res <- bench::mark( | |
rank_average = rank(x, ties.method = "average"), | |
rank_first = rank(x, ties.method = "first"), | |
rank_last = rank(x, ties.method = "last"), | |
rank_min = rank(x, ties.method = "min"), | |
rank_max = rank(x, ties.method = "max"), | |
frank_average = data.table::frank(x, ties.method = "average"), | |
frank_first = data.table::frank(x, ties.method = "first"), | |
frank_last = data.table::frank(x, ties.method = "last"), | |
frank_random = data.table::frank(x, ties.method = "random"), | |
frank_max = data.table::frank(x, ties.method = "max"), | |
frank_min = data.table::frank(x, ties.method = "min"), | |
frank_dense = data.table::frank(x, ties.method = "dense"), | |
order_auto = order(x, method = "auto"), | |
order_shell = order(x, method = "shell"), | |
order_radix = order(x, method = "radix"), | |
limited_auto = rank_limited(x, method = "auto"), | |
limited_shell = rank_limited(x, method = "shell"), | |
limited_quick = rank_limited(x, method = "quick"), | |
limited_radix = rank_limited(x, method = "radix"), | |
limited2_auto = rank_limited2(x, method = "auto"), | |
limited2_shell = rank_limited2(x, method = "shell"), | |
limited2_quick = rank_limited2(x, method = "quick"), | |
limited2_radix = rank_limited2(x, method = "radix"), | |
check = FALSE | |
) | |
print(res, n = Inf) | |
#> # A tibble: 23 x 13 | |
#> expression min median `itr/sec` mem_alloc `gc/sec` n_itr n_gc | |
#> <bch:expr> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl> <int> <dbl> | |
#> 1 rank_average 1.04ms 1.24ms 767. 421.96KB 4.06 378 2 | |
#> 2 rank_first 428.3us 508.7us 1843. 381.75KB 12.6 879 6 | |
#> 3 rank_last 443.4us 510.2us 1840. 430.16KB 15.1 852 7 | |
#> 4 rank_min 1.01ms 1.15ms 817. 351.95KB 6.19 396 3 | |
#> 5 rank_max 1.01ms 1.16ms 811. 351.95KB 4.06 399 2 | |
#> 6 frank_average 1.25ms 1.35ms 705. 2.06MB 4.05 348 2 | |
#> 7 frank_first 1.54ms 1.64ms 587. 119.06KB 0 294 0 | |
#> 8 frank_last 1.26ms 1.38ms 689. 143.78KB 4.07 339 2 | |
#> 9 frank_random 2.27ms 2.49ms 388. 219.57KB 0 194 0 | |
#> 10 frank_max 1.26ms 1.42ms 645. 143.78KB 2.02 320 1 | |
#> 11 frank_min 1.26ms 1.41ms 670. 143.78KB 2.01 333 1 | |
#> 12 frank_dense 1.25ms 1.44ms 638. 143.78KB 2.02 316 1 | |
#> 13 order_auto 316.3us 363.6us 2506. 39.11KB 2.02 1243 1 | |
#> 14 order_shell 908.7us 1.04ms 917. 39.11KB 2.02 455 1 | |
#> 15 order_radix 308.8us 357.7us 2559. 39.11KB 2.02 1269 1 | |
#> 16 limited_auto 708.7us 845.6us 1108. 524.2KB 10.4 531 5 | |
#> 17 limited_shell 824.5us 956.55us 977. 546.61KB 10.4 468 5 | |
#> 18 limited_quick 754.9us 904.1us 1041. 521.43KB 10.4 499 5 | |
#> 19 limited_radix 712.4us 835us 1140. 521.43KB 10.4 550 5 | |
#> 20 limited2_auto 648.8us 786.9us 1186. 436.53KB 10.4 568 5 | |
#> 21 limited2_shell 908us 1.05ms 891. 447.94KB 6.15 435 3 | |
#> 22 limited2_quick 799.2us 914.85us 1043. 436.53KB 10.4 500 5 | |
#> 23 limited2_radix 646.4us 789.3us 1202. 436.53KB 8.26 582 4 | |
#> # ... with 5 more variables: total_time <bch:tm>, result <list>, memory <list>, | |
#> # time <list>, gc <list> | |
res <- res[order(res$`itr/sec`), ] | |
res$expression <- mark::fact(as.character(res$expression)) | |
mark::flip(tail(res)) | |
#> # A tibble: 6 x 6 | |
#> expression min median `itr/sec` mem_alloc `gc/sec` | |
#> <fct> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl> | |
#> 1 order_radix 309us 358us 2559. 39.1KB 2.02 | |
#> 2 order_auto 316us 364us 2506. 39.1KB 2.02 | |
#> 3 rank_first 428us 509us 1843. 381.8KB 12.6 | |
#> 4 rank_last 443us 510us 1840. 430.2KB 15.1 | |
#> 5 limited2_radix 646us 789us 1202. 436.5KB 8.26 | |
#> 6 limited2_auto 649us 787us 1186. 436.5KB 10.4 | |
ggplot2::autoplot(res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment