Hi,

I'm new to Ruby, and I've just tried to measure it's performance
compared to Python, and got some interesting results.

The Ruby test script is:

#!/usr/bin/env ruby

s = ""
i = 0
while line = gets
  s += line
  i += 1
  puts(i) if i % 1000 == 0
end

and the Python one:

#!/usr/bin/env python

import sys

s = ""
i = 0
for line in sys.stdin:
  s += line
  i += 1
  if i % 1000 == 0: print i


I fed a 1MB-large file as input to each of this script. The strange
thing is that the Ruby version starts to output progress slower and
slower as the s string grows. The Python version went smoothly.

Looks like a memory management issue with Ruby. I wonder if this is
going to be significantly improved in subsequent releases of Ruby? I
was testing with Ruby 1.8.6, and Python 2.5.1. (I also tried Python
2.3 and it was significantly slower than 2.5)

As I said, I'm new to Ruby, but want to use it for a long term
project, and would like to know more about it's performance specifics.

Thanks for any clarification in advance!