Hacker News new | ask | show | jobs
by cutler 2098 days ago
If that's the case why is Ruby slower?
2 comments

Your Ruby snippet is slower for two reasons:

  - IO.foreach is lazy, but then you call `Array#grep` on it which allocate a huge Array
  - `grep` populate the "last_match" object, `String#match?` is much faster.
Try rifraf's snippet: https://news.ycombinator.com/item?id=24597067, it should be as fast as Python.
Because what you’re really measuring is something like how well the block size the interpreter uses for IO matches the underlying os/hardware
If they are both doing similar things and one is faster that's still significant. So Python's i/o is faster than Ruby's.