Skip to content

Instantly share code, notes, and snippets.

@yutannihilation
Created March 20, 2021 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yutannihilation/5c6b95ff595235e86fee854da071a080 to your computer and use it in GitHub Desktop.
Save yutannihilation/5c6b95ff595235e86fee854da071a080 to your computer and use it in GitHub Desktop.

c.f. https://github.com/coolbutuseless/fugly#simple-benchmark

library(ore)
library(unglue)
library(ggplot2)

# meaningless strings for benchmarking
string <- paste0("Information name:greg age:", 1:1000)

res <- bench::mark(
  `fugly::str_capture()` = fugly::str_capture(string, "name:{name} age:{age=\\d+}"),
  `unglue::unglue()` = unglue::unglue_data(string, "Information name:{name} age:{age=\\d+}"),
  `utils::strcapture()` = utils::strcapture("Information name:(.*?) age:(\\d+)", string, 
                                            proto = data.frame(name=character(), age=character())),
  `ore::ore_search()` = do.call(rbind.data.frame, lapply(ore_search(ore('name:(?<name>.*?) age:(?<age>\\d+)', encoding='utf8'), string, all=TRUE), function(x) {x$groups$matches})),
  `rr4r::rr4r_extract_groups()` = rr4r::rr4r_extract_groups(string, "name:(?P<name>.*?) age:(?P<age>\\d+)"),
  # rr4r_extract_groups() returns tibble, so stop checking
  check = FALSE
)
#> Warning: Some expressions had a GC in every iteration; so filtering is disabled.

plot(res) + theme_bw()
#> Loading required namespace: tidyr

Created on 2021-03-20 by the reprex package (v1.0.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment