Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance #9

Merged
merged 5 commits into from
Apr 5, 2023
Merged

Improve performance #9

merged 5 commits into from
Apr 5, 2023

Conversation

Bisaloo
Copy link
Owner

@Bisaloo Bisaloo commented Apr 5, 2023

Fix #8

~ x10 perf improvement

```r
library(microbenchmark)

x <- c("{{ test }}", "a", "{{ b }}", NA)

marker_open <- "{{"
marker_close <- "}}"

microbenchmark(
  { !is.na(x) & startsWith(x, marker_open) & endsWith(x, marker_close) } ,
  {
    esc_markers <- gsub("(\\[|\\]|[{}*?+()\\.|\\(\\)^$\\])", "\\\\\\1", c(marker_open, marker_close))

    grepl(
      paste0("^", esc_markers[1], ".*", esc_markers[2], "$"),
      x
    )
  },
  check = "identical"
)
```
since we know for sure we're only working with strings that have the markers
@Bisaloo Bisaloo merged commit 77ae014 into main Apr 5, 2023
@Bisaloo Bisaloo deleted the performance branch April 5, 2023 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve performance
1 participant