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
| benchmark({ | |
| key_to_lookup <- select_random_key() | |
| time(data_table[.(key_to_lookup), nomatch = 0L]) | |
| }) | |
| ## min max mean | |
| ## 0.00200 0.01200 0.00455 |
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
| time(setkey(data_table, col1)) | |
| 5.645 |
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
| # Try it yourself: | |
| environment_source <- setNames(as.list(data$col2), data$col1) | |
| time(as.environment(environment_source)) |
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
| benchmark({ | |
| key_to_lookup <- select_random_key() | |
| time(data[which(data$col1 == key_to_lookup),]) | |
| }) | |
| ## min max mean | |
| ## 0.09200 0.15800 0.10471 |
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
| benchmark({ | |
| key_to_lookup <- select_random_key() | |
| time(data[data$col1 == key_to_lookup,]) | |
| }) | |
| ## min max mean | |
| ## 0.09800 0.22300 0.11424 |
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
| library(data.table) | |
| data_table <- data.table(data) | |
| benchmark({ | |
| key_to_lookup <- select_random_key() | |
| time(data_table[col1 == key_to_lookup]) | |
| }) | |
| ## min max mean |
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
| library(dplyr) | |
| benchmark({ | |
| key_to_lookup <- select_random_key() | |
| time(data %>% filter(col1 == key_to_lookup)) | |
| }) | |
| ## min max mean | |
| ## 0.0960 0.2440 0.1124 |
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
| time <- function(...) { | |
| time_measurement <- system.time(eval(...)) | |
| time_measurement[["user.self"]] | |
| } | |
| benchmark <- function(..., n = 100) { | |
| times <- replicate(n, ...) | |
| c(min = min(times), max = max(times), mean = mean(times)) | |
| } |
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
| library(tibble) | |
| random_string_column <- function(n) { | |
| stringi::stri_rand_strings(n = n, length = 8) | |
| } | |
| random_data_frame <- function(n) tibble( | |
| col1 = random_string_column(n), | |
| col2 = random_string_column(n) | |
| ) |
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
| d$make_sound(sound = "Woooof!") |
NewerOlder