Skip to content

Instantly share code, notes, and snippets.

@traversc
Last active March 27, 2022 00:49
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 traversc/f357c5f1a4b0368649849dd3d1f49d14 to your computer and use it in GitHub Desktop.
Save traversc/f357c5f1a4b0368649849dd3d1f49d14 to your computer and use it in GitHub Desktop.
Benching stringi with and without altrep
library(stringi) # devtools::install_github("traversc/stringi")
library(tictoc)
enwik8 <- readLines("~/Downloads/enwik8", warn = F)
search <- c("Wikipedia", "^.")
replace <- c("Encyclopedia", "")
tic("WITHOUT alt rep")
stri_use_alt_rep(FALSE); result <- stri_replace_all_regex(enwik8, search, replace, vectorize_all = F)
toc()
library(stringi) # devtools::install_github("traversc/stringi")
library(tictoc)
enwik8 <- readLines("~/Downloads/enwik8", warn = F)
search <- c("Wikipedia", "^.")
replace <- c("Encyclopedia", "")
tic("WITH alt rep")
stri_use_alt_rep(TRUE); result <- stri_replace_all_regex(enwik8, search, replace, vectorize_all = F)
toc()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment