From: brabuhr@... Date: 2009-08-20T02:26:46+09:00 Subject: Re: Confirm my Performance Test Against Java? On Wed, Aug 19, 2009 at 11:07 AM, Reid Thompson wrote: > brabuhr@gmail.com wrote: >> >> On Wed, Aug 19, 2009 at 9:31 AM, Ben Christensen >> 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? > > If it is, then you should just do > $ time wc approach.txt >  6836  78325 484114 approach.txt :-) I got a little crazy; first the numbers (slower hardware this time): > uname -a Linux eXist 2.6.28-14-generic #47-Ubuntu SMP Sat Jul 25 00:28:35 UTC 2009 i686 GNU/Linux > java -version java version "1.6.0_0" OpenJDK Runtime Environment (IcedTea6 1.4.1) (6b14-1.4.1-0ubuntu11) OpenJDK Client VM (build 14.0-b08, mixed mode, sharing) > java FileReadParse Starting to read file... The number of tokens is: 479623 It took 596 ms > /opt/matzruby/trunk/bin/ruby -v -rubygems file_read_parse.rb ruby 1.9.2dev (2009-08-14 trunk 24539) [i686-linux] Starting to read file ... The number of tokens is: 479623 It took 1751.92544 ms > /opt/matzruby/trunk/bin/ruby -v -rubygems file_read_parse-3.rb ruby 1.9.2dev (2009-08-14 trunk 24539) [i686-linux] ffi_c.so: warning: method redefined; discarding old inspect struct.rb:26: warning: method redefined; discarding old offset variadic.rb:15: warning: method redefined; discarding old call library.rb:78: warning: method redefined; discarding old fopen library.rb:78: warning: method redefined; discarding old fgetc Starting to read file ... It took 4565.077896 ms The number of tokens is: 479623 > jruby -v -rubygems file_read_parse.rb jruby 1.3.0 (ruby 1.8.6p287) (2009-06-03 5dc2e22) (OpenJDK Client VM 1.6.0_0) [i386-java] Starting to read file ... The number of tokens is: 479623 It took 2316.0 ms > jruby -v -rubygems file_read_parse-3.rb jruby 1.3.0 (ruby 1.8.6p287) (2009-06-03 5dc2e22) (OpenJDK Client VM 1.6.0_0) [i386-java] Starting to read file ... It took 3117.0 ms The number of tokens is: 479623 And the code: > cat file_read_parse-3.rb require 'ffi' module LibC extend FFI::Library # FILE *fopen(const char *path, const char *mode); attach_function :fopen, [ :string, :string ], :pointer # int fgetc(FILE *stream); attach_function :fgetc, [ :pointer ], :int end puts "Starting to read file ..." start = Time.now file = LibC.fopen("/tmp/file_test.txt", "r") count = 0; in_word = false while (c = LibC.fgetc(file)) != -1 if 32 < c and c < 127 unless in_word count += 1 in_word = true end else in_word = false end end stop = Time.now puts "It took #{(stop - start) * 1000} ms" puts "The number of tokens is: #{count}"