Hi all! I’ve just run an experiment to see how Ruby 1.8.0p2 and Ruby 1.6.8 compared to Python 2.2.2 on Mandrake Linux 9.0. For this I used a 1GB Dell workstation with dual Xeon CPUs and dual SCSI 18GB disks. I tried to test basic sequential text file I/O, string.split(";") and hashing. The test CSV file was reasonably large (around 400MBytes and 3.5 million lines).
The timmings I’ve got are:
Ruby 1.6.8 on Linux
···
===============
Test 1 --> elapsed time to read the full file, line by line, and counting the number of lines ==> 23 seconds
Test 2 --> the same as above but now including for each line read
fields = line.split(";", -1)
n_fields += fields.length
==> 57 seconds (delta=34 seconds for the extra string.split stuff)
Test 3 --> the same as Test 2 but now adding an hash table (table=Hash.new(0)) to count all occurrences of different values for fields[5]
table[fields[5]] += 1
==> 65 seconds (delta=8 seconds for the extra hashing stuff)
Ruby 1.8.0p2 also on Linux
Test 1 --> 7 seconds (3 times faster than version 1.6.8 !!!)
Test 2 --> 83 seconds (delta=76 secs --> quite slower than version 1.6.8!!!)
Test 3 --> 91 seconds (delta=8 secs --> same speed as version 1.6.8)
First conclusion: 1.8.0p2 is much faster than version 1.6.8 for basic sequential text I/O but string operations like str.split(";", -1) seem to be 50% slower! Any reason for this?
Python 2.2.2 also on Linux
Test 1 --> 8 secs (aprox. the same speed as Ruby 1.8.0p2)
Test 2 --> 62 secs (delta=54 secs, a bit faster than Ruby 1.6.8)
Test 3 --> 73 secs (delta=9 secs --> a tiny bit slower than Ruby 1.8.0p2 or 1.6.8)
So, at least for these very very basic operations Ruby compares well with Python. Any idea why Ruby 1.8.0p2 is slower than version 1.6.8 for such a basic operation like string.split(";", -1) ?
Regards,
J. Alegria
BTW: While Python on Windows Xp (on the same machine) is almost as fast as on Linux the same doesnt’t seem true for Ruby. The Windows version is slower than the linux one!