Skip to content

Instantly share code, notes, and snippets.

@yutannihilation
Last active February 27, 2021 02:59
Show Gist options
  • Save yutannihilation/23ed6616313a176dd5e31d0281dfbfa4 to your computer and use it in GitHub Desktop.
Save yutannihilation/23ed6616313a176dd5e31d0281dfbfa4 to your computer and use it in GitHub Desktop.
library(stringr)
library(ggplot2)
library(rr4r)

ptn <- r"([\w]+://[^/\s?#]+[^\s?#]+(?:\?[^\s#]*)?(?:#[^\s]*)?)"
url <- "https://mail.google.com/mail/u/0/"

res1 <- bench::press(
  x = c(1, 1e3, 1e5),
  {
    bench::mark(
      stringr = str_detect(rep(url, x),  ptn),
      rr4r    = rr4r_detect(rep(url, x), ptn),
      min_iterations = 100
    )
  }
)
#> Running with:
#>        x
#> 1      1
#> 2   1000
#> 3 100000

autoplot(res1) +
  ggtitle("Detection")
#> Loading required namespace: tidyr

res2 <- bench::press(
  x = c(1, 1e3, 1e5),
  {
    bench::mark(
      stringr = str_extract(rep(url, x),  ptn),
      rr4r    = rr4r_extract(rep(url, x), ptn),
      min_iterations = 100
    )
  }
)
#> Running with:
#>        x
#> 1      1
#> 2   1000
#> 3 100000

autoplot(res2) +
  ggtitle("Extraction")

Created on 2021-02-27 by the reprex package (v1.0.0)

library(stringr)
library(ggplot2)
library(rr4r)

ptn <- r"([\w]+://[^/\s?#]+[^\s?#]+(?:\?[^\s#]*)?(?:#[^\s]*)?)"
url <- "https://mail.google.com/mail/u/0/"

res1 <- bench::press(
  x = c(1, 1e3, 1e5),
  {
    bench::mark(
      stringr = str_detect(rep(url, x),  ptn),
      rr4r    = rr4r_detect(rep(url, x), ptn),
      min_iterations = 100
    )
  }
)
#> Running with:
#>        x
#> 1      1
#> 2   1000
#> 3 100000

autoplot(res1) +
  ggtitle("Detection")
#> Loading required namespace: tidyr

res2 <- bench::press(
  x = c(1, 1e3, 1e5),
  {
    bench::mark(
      stringr = str_extract(rep(url, x),  ptn),
      rr4r    = rr4r_extract(rep(url, x), ptn),
      min_iterations = 100
    )
  }
)
#> Running with:
#>        x
#> 1      1
#> 2   1000
#> 3 100000

autoplot(res2) +
  ggtitle("Extraction")

Created on 2021-02-27 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