|
|
|
|
|
by cutler
2093 days ago
|
|
Much as I would love to believe Ruby 3.0 delivers some kind of speed bump my simple test of doing what Ruby supposedly does best - parsing a log file with a regex - shows Ruby 16% slower than the Python equivalent. Ruby
puts IO.foreach('logs1.txt').grep /\b\w{15}\b/
Python
from re import compile
with open('logs1.txt', 'r') as fh:
regex = compile(r'\b\w{15}\b')
for line in fh:
if regex.search(line): print(line, end='')
On my MacBook Pro (2013) running Catalina Ruby averaged 1.49 secs and Python 1.27 secs. The file `logs1.txt` is a 20Mb Apache log file. Pre-compilation with: reg = Regex.compile /\b\w{15}\b/
puts IO.foreach('logs1.txt').grep reg
... slowed Ruby down to 1.57 secs.Using --jit didn't change Ruby's overall time but considering it adds 700ms to Ruby's startup time execution time was faster. |
|