Skip to content

Commit 4c70b03

Browse files
committed
Merge branch 'nitely-nim_regex'
2 parents 9e4e886 + 39b1bc3 commit 4c70b03

File tree

3 files changed

+40
-11
lines changed

3 files changed

+40
-11
lines changed

Dockerfile

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ RUN apt-get update && \
1414
software-properties-common \
1515
tzdata \
1616
unzip \
17-
wget
17+
wget \
18+
git
1819

1920
# Set the locale and timezone
2021
RUN locale-gen en_US.UTF-8 && \
@@ -92,7 +93,8 @@ RUN wget -q https://github.com/JetBrains/kotlin/releases/download/v1.3.50/kotlin
9293

9394
## Nim
9495
RUN curl https://nim-lang.org/choosenim/init.sh -sSf | sh -s -- -y && \
95-
ln -s /root/.nimble/bin/nim /usr/local/bin/nim
96+
ln -s /root/.nimble/bin/nim /usr/local/bin/nim && \
97+
/root/.nimble/bin/nimble install regex -y
9698

9799
## PHP
98100
RUN apt-get install -yq --no-install-recommends \
@@ -107,18 +109,18 @@ RUN apt-get install -yq --no-install-recommends \
107109
python3.6
108110

109111
## Pyhton2 - PyPy2
110-
RUN wget -q https://bitbucket.org/pypy/pypy/downloads/pypy2.7-v7.2.0-linux64.tar.bz2 -O pypy2.7-v7.2.0-linux64.tar.bz2 && \
111-
tar -x -C /opt -f pypy2.7-v7.2.0-linux64.tar.bz2 && \
112-
mv /opt/pypy2.7-v7.2.0-linux64 /opt/pypy2 && \
112+
RUN wget -q https://downloads.python.org/pypy/pypy2.7-v7.3.3-linux64.tar.bz2 -O pypy2.7-v7.3.3-linux64.tar.bz2 && \
113+
tar -x -C /opt -f pypy2.7-v7.3.3-linux64.tar.bz2 && \
114+
mv /opt/pypy2.7-v7.3.3-linux64 /opt/pypy2 && \
113115
ln -s /opt/pypy2/bin/pypy /usr/local/bin/pypy2 && \
114-
rm pypy2.7-v7.2.0-linux64.tar.bz2
116+
rm pypy2.7-v7.3.3-linux64.tar.bz2
115117

116118
## Pyhton3 - PyPy3
117-
RUN wget -q https://bitbucket.org/pypy/pypy/downloads/pypy3.6-v7.2.0-linux64.tar.bz2 -O pypy3.6-v7.2.0-linux64.tar.bz2 && \
118-
tar -x -C /opt -f pypy3.6-v7.2.0-linux64.tar.bz2 && \
119-
mv /opt/pypy3.6-v7.2.0-linux64 /opt/pypy3 && \
119+
RUN wget -q https://downloads.python.org/pypy/pypy3.6-v7.3.3-linux64.tar.bz2 -O pypy3.6-v7.3.3-linux64.tar.bz2 && \
120+
tar -x -C /opt -f pypy3.6-v7.3.3-linux64.tar.bz2 && \
121+
mv /opt/pypy3.6-v7.3.3-linux64 /opt/pypy3 && \
120122
ln -s /opt/pypy3/bin/pypy3 /usr/local/bin/pypy3 && \
121-
rm pypy3.6-v7.2.0-linux64.tar.bz2
123+
rm pypy3.6-v7.3.3-linux64.tar.bz2
122124

123125
## Ruby
124126
RUN apt-get install -yq --no-install-recommends \

nim/benchmark_regex.nim

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import times
2+
import os
3+
import strformat
4+
5+
import pkg/regex
6+
7+
if paramCount() == 0:
8+
echo "Usage: ./benchmark <filename>"
9+
quit(QuitFailure)
10+
11+
proc measure(data: string, pattern: string) =
12+
let time = cpuTime()
13+
let r_pattern = re(pattern)
14+
let matches = data.findAll(r_pattern)
15+
let count = len(matches)
16+
let elapsed_time = cpuTime() - time
17+
echo &"{elapsed_time * 1e3} - {count}"
18+
19+
let data = readFile(paramStr(1))
20+
21+
measure(data, r"[\w\.+-]+@[\w\.-]+\.[\w\.-]+")
22+
23+
measure(data, r"[\w]+://[^/\s?#]+[^\s?#]+(?:\?[^\s#]*)?(?:#[^\s]*)?")
24+
25+
measure(data, 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])")

run-benchmarks.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
'D dmd' => 'dmd -O -release -inline -of=d/bin/benchmark d/benchmark.d',
1515
'D ldc' => 'ldc2 -O3 -release -of=d/bin/benchmark-ldc d/benchmark.d',
1616
'Dart Native' => 'mkdir -p /var/regex/dart/bin && dart2native dart/benchmark.dart -o dart/bin/benchmark',
17-
'Go' => 'go build -ldflags "-s -w" -o go/bin/benchmark ./go',
17+
'Go' => 'go env -w GO111MODULE=auto && go build -ldflags "-s -w" -o go/bin/benchmark ./go',
1818
'Java' => 'javac java/Benchmark.java',
1919
'Kotlin' => 'kotlinc kotlin/benchmark.kt -include-runtime -d kotlin/benchmark.jar',
2020
'Nim' => 'nim c -d:release --opt:speed --verbosity:0 -o:nim/bin/benchmark nim/benchmark.nim',
21+
'Nim Regex' => 'nim c -d:release --opt:speed --verbosity:0 -o:nim/bin/benchmark_regex nim/benchmark_regex.nim',
2122
'Rust' => 'cargo build --quiet --release --manifest-path=rust/Cargo.toml',
2223
];
2324

@@ -37,6 +38,7 @@
3738
'Javascript' => 'node javascript/benchmark.js',
3839
'Kotlin' => 'kotlin kotlin/benchmark.jar',
3940
'Nim' => 'nim/bin/benchmark',
41+
'Nim Regex' => 'nim/bin/benchmark_regex',
4042
'Perl' => 'perl perl/benchmark.pl',
4143
'PHP' => 'php php/benchmark.php',
4244
'Python 2' => 'python2.7 python/benchmark.py',

0 commit comments

Comments
 (0)