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

Add R version #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ RUN wget -q https://downloads.python.org/pypy/pypy3.6-v7.3.3-linux64.tar.bz2 -O
ln -s /opt/pypy3/bin/pypy3 /usr/local/bin/pypy3 && \
rm pypy3.6-v7.3.3-linux64.tar.bz2

## R
RUN apg-get install -yq --no-install-recommends \
r-base r-cran-stringr r-cran-readr

## Ruby
RUN apt-get install -yq --no-install-recommends \
ruby-full
Expand Down
8 changes: 8 additions & 0 deletions r/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# R Regex Benchmark

## How to run

```sh
# R
Rscript --vanilla benchmark.R <filename>
```
30 changes: 30 additions & 0 deletions r/benchmark.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env Rscript
library(stringr)
library(readr)

measure <- function(data, pattern) {
start <- Sys.time()
# res <- length(regmatches(data, gregexpr(pattern, data, perl = TRUE))[[1]])
res <- str_count(data, pattern)
end <- Sys.time()
s <- end - start
out <- paste0(format(as.numeric(s)*1e3, digits = 3), " - ", res)
print(out)
}

args = commandArgs(trailingOnly=TRUE)

if (length(args)==0) {
stop("At least one argument must be supplied (input file).n", call.=FALSE)
}

file_str <- read_file(args[1])

# Email
measure(file_str, r"{[\w\\.+-]+@[\w\.-]+\.[\w\.-]+}")

# URI
measure(file_str, r"{[\w]+://[^/\s?#]+[^\s?#]+(?:\?[^\s#]*)?(?:#[^\s]*)?}")

# IPv4
measure(file_str, r"{(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9])}")
1 change: 1 addition & 0 deletions run-benchmarks.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
'Python 3' => 'python3.6 python/benchmark.py',
'Python PyPy2' => 'pypy2 python/benchmark.py',
'Python PyPy3' => 'pypy3 python/benchmark.py',
'R' => 'Rscript --vanilla r/benchmark.R',
'Ruby' => 'ruby ruby/benchmark.rb',
'Rust' => 'rust/target/release/benchmark',
];
Expand Down