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)