On Wed, Aug 19, 2009 at 9:31 AM, Ben Christensen
<benjchristensen / gmail.com> wrote:
> I'm evaluating Ruby for use in a variety of systems that are planned by
> default to be Java.
>
> I've started down a path of doing various performance tests to see what
> kind of impact will occur by using Ruby and in my first test the numbers
> are very poor - so poor that I have to question if I'm doing something
> wrong.

Is this test case in any way representative of the tasks you will
actually be performing?

Test file 1:

> uname -a
Linux linux116.ctc.com 2.6.18-92.1.22.el5 #1 SMP Tue Dec 16 12:03:43
EST 2008 i686 i686 i386 GNU/Linux

> java -version
java version "1.6.0_0"
IcedTea6 1.3.1 (6b12-Fedora-EPEL-5) Runtime Environment (build 1.6.0_0-b12)
OpenJDK Server VM (build 1.6.0_0-b12, mixed mode)

> java FileReadParse
Starting to read file...
The number of tokens is: 1954
It took 16 ms

> ruby -v file_read_parse.rb
ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-linux]
Starting to read file ...
The number of tokens is: 1954
It took 4.951 ms

Test file 2:

> java FileReadParse
Starting to read file...
The number of tokens is: 479623
It took 337 ms

> ruby file_read_parse.rb
Starting to read file ...
The number of tokens is: 479623
It took 2526.455 ms

> ruby file_read_parse-2.rb
Starting to read file ...
It took 588.065 ms
The number of tokens is: 479623

> cat file_read_parse-2.rb
puts "Starting to read file ..."
start = Time.now

tokens = File.new("/tmp/file_test.txt").read.scan(/[^\s]+/)
count = tokens.size

stop = Time.now
puts "It took #{(stop - start) * 1000} ms"
puts "The number of tokens is: #{count}"