From: Reid Thompson Date: 2009-08-20T04:11:49+09:00 Subject: Re: Confirm my Performance Test Against Java? Robert Klemme wrote: > On 19.08.2009 15:31, Ben Christensen wrote: > >> http://benjchristensen.com/2009/08/18/initial-impressions-on-ruby-performance/ >> > > 1.9* is significantly better. I did not try JRuby yet. > > robert@fussel /cygdrive/c/Temp/frp > $ /cygdrive/c/Programme/Java/jdk1.6.0_14/bin/javac FileReadParse.java > > robert@fussel /cygdrive/c/Temp/frp > $ java -cp . FileReadParse > Starting to read file... > The number of tokens is: 1122 > It took 16 ms > > robert@fussel /cygdrive/c/Temp/frp > $ allruby file_read_parse.rb > ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-cygwin] > Starting to read file ... > The number of tokens is: 1122 > It took 3.0 ms > ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-cygwin] > Starting to read file ... > The number of tokens is: 1122 > It took 2.0 ms > > robert@fussel /cygdrive/c/Temp/frp > $ wc file_test.txt > 190 1114 7579 file_test.txt > > robert@fussel /cygdrive/c/Temp/frp > $ > > > ==================================================================== > > > robert@fussel /cygdrive/c/Temp/frp > $ !w > wc file_test.txt x > 95000 557000 3789500 file_test.txt > 68970 404382 2751177 x > 163970 961382 6540677 insgesamt > > robert@fussel /cygdrive/c/Temp/frp > $ java -cp . FileReadParse > Starting to read file... > The number of tokens is: 561000 > It took 359 ms > > robert@fussel /cygdrive/c/Temp/frp > $ !a > allruby file_read_parse.rb > ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-cygwin] > Starting to read file ... > The number of tokens is: 561000 > It took 1395.0 ms > ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-cygwin] > Starting to read file ... > The number of tokens is: 561000 > It took 872.0 ms > > robert@fussel /cygdrive/c/Temp/frp > > robert@fussel /cygdrive/c/Temp/frp > $ /cygdrive/c/Programme/Java/jdk1.6.0_14/bin/java -server -cp . > FileReadParse > Starting to read file... > The number of tokens is: 561000 > It took 515 ms > > robert@fussel /cygdrive/c/Temp/frp > $ > > Cheers > > robert > $ java FileReadParse Starting to read file... The number of tokens is: 284717 It took 333 ms rthompso@raker>~ $ ruby wcinline.rb uscities.txt Starting to read file ... 284717 It took 211.72 ms rthompso@raker>~ $ time wc uscities.txt 141989 284717 7449038 uscities.txt real 0m0.333s user 0m0.307s sys 0m0.006s $ java -version java version "1.6.0_15" Java(TM) SE Runtime Environment (build 1.6.0_15-b03) Java HotSpot(TM) Server VM (build 14.1-b02, mixed mode) $ ruby -v ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-linux] Not sure how Gentoo handles the java, but all other exes on the box are compiled CFLAGS="-march=prescott -O2 -g -pipe" with splitdebug enabled dual core Linux raker 2.6.30-gentoo-r4 #2 SMP PREEMPT Wed Aug 5 11:51:00 EDT 2009 i686 Intel(R) Core(TM)2 CPU 6320 @ 1.86GHz GenuineIntel GNU/Linux wcinline.rb quickly hacked from http://en.literateprograms.org/Special:Downloadcode/Word_count_%28C%29 and http://github.com/remogatto/ffi-inliner/blob/90481c869d9fc0778e12218d3ffa83e3f823acaf/examples/ex_1.rb $ cat wcinline.rb require 'ffi-inliner' module MyLib extend Inliner inline '#include #include int n; void wc(const char *fname) { int ch; int chars=0; int words=0; int lines=0; int sp=1; FILE *fp; if(fname[0]!=055) fp=fopen(fname, "r"); else fp=stdin; if(!fp) return -1; while((ch=getc(fp))!=EOF) { if(isspace(ch)) sp=1; else if(sp) { ++words; sp=0; } } if(fname[0]!=055) fclose(fp); printf("% 8d\n", words); }' end class Foo include MyLib end # get the start time start = Time.now puts "Starting to read file ..." Foo.new.wc(ARGV[0]) puts "It took " + ((Time.now-start)*1000).to_s + " ms"