3 ms·
The programs aren't doing the same things. The Ruby one seems to buffer the matches into a huge string then print. Don't know how different it would be but bett
by karmakaze 6y ago
The programs aren't doing the same things. The Ruby one seems to buffer the matches into a huge string then print. Don't know how different it would be but better to compare apples.
- riffraff 6y agoProbably the equivalent thing to test would be regexp = /\b\w{15}\b/ IO.foreach('logs1.txt') do |line| puts line if regexp.match?(line) end I imagine this will in both cases mostly be testing the computer's IO. Regexp.compile doesn't do anything substantially different from Regexp.new or a literal (i.e. it doesn't optimize the regular expression or something) so I think the difference is just random fluctuations.
- deleted 6y ago[deleted]
- cutler 6y agoIO.foreach without a block returns an enumerator.
- cutler 6y agoYou may be right. This version: IO.foreach('logs1.txt') {|x| puts x if /\b\w{15}\b/.match? x } ... runs in 1.3 secs, ie. same time as Python. Still, I exepcted Ruby 3x3 to beat standard Python.