Hacker News new | ask | show | jobs
by karmakaze 2095 days 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.
2 comments

Probably 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.

IO.foreach without a block returns an enumerator.
You 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.