This reminded me of an ancient thread (
Re: Interesting Perl/Java regexp benchmarking), and sure enough, Perl is faster in the negative case e.g.
% hyperfine --warmup 3 'perl re.pl sample.txt' 'python3 re.py sample.t
+xt'
Benchmark 1: perl re.pl sample.txt
Time (mean ± σ): 232.9 ms ± 2.2 ms [User: 132.1 ms, Sy
+stem: 99.5 ms]
Range (min … max): 230.8 ms … 238.4 ms 12 runs
Benchmark 2: python3 re.py sample.txt
Time (mean ± σ): 373.3 ms ± 5.6 ms [User: 246.1 ms, Sy
+stem: 125.4 ms]
Range (min … max): 365.5 ms … 383.7 ms 10 runs
Summary
perl re.pl sample.txt ran
1.60 ± 0.03 times faster than python3 re.py sample.txt
All I changed was the separator for the number pair in the regex to ";" i.e.
mul\(\d{1,3};\d{1,3}\)
I used choroba's
method to generate the sample (but with 10_000_000 lines).
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.