Is it normal that printing “1” requires more than five second? Sorry my
english.
I am new to ruby, currently I use PHP and Perl in Windows, but I don’t
like PHP and Perl is not 100% compatible to Windows (nor Ruby, as I
see). I have found JRuby which claimed itself fully cross-platform. I
tried it, but it starts very-very slow. I have AMD 64 3000+, 1 Gb DDR,
Windows7, Java 6u17.
I have created a simple test (as I seen here:
JRuby startup very slow - JRuby - Ruby-Forum): I runned the programs ten times
and get the average run time. Here are the results (in seconds):
0.1 perl -e “print 1”
0.1 ruby-1.9 -e “puts 1”
0.2 php -r “print(1);”
0.5 ruby-1.8 -e “puts 1”
1.9 jruby-1.2.0 -e “puts 1”
2.1 jruby-1.3.1 -e “puts 1”
5.6 jruby-1.4 -e “puts 1”
5.3 jruby-1.4 --1.9 -e “puts 1”
Content of t:\benchmark.rb
require ‘benchmark’
def fib_ruby(n)
if n < 2
n
else
fib_ruby(n - 2) + fib_ruby(n - 1)
end
end
TIMES = (ARGV[0] || 5).to_i
N = (ARGV[1] || 30).to_i
TIMES.times {
puts Benchmark.measure { fib_ruby(N) }
}
c:\Programs\ruby\bin\ruby.exe t:\benchmark.rb
4.172000 0.000000 4.172000 ( 4.934000)
4.265000 0.000000 4.265000 ( 5.245000)
4.203000 0.000000 4.203000 ( 5.141000)
4.250000 0.000000 4.250000 ( 4.943000)
4.141000 0.000000 4.141000 ( 4.924000)
t:\ruby-1.9\bin\ruby.exe t:\benchmark.rb
2.328000 0.000000 2.328000 ( 2.992187)
2.391000 0.000000 2.391000 ( 2.759766)
2.328000 0.000000 2.328000 ( 2.704102)
2.375000 0.000000 2.375000 ( 2.836914)
2.406000 0.000000 2.406000 ( 2.768555)
t:\jruby-1.2.0\bin\jruby.bat t:\benchmark.rb
1.340000 0.000000 1.340000 ( 1.259000)
1.176000 0.000000 1.176000 ( 1.178000)
1.167000 0.000000 1.167000 ( 1.167000)
1.193000 0.000000 1.193000 ( 1.193000)
1.177000 0.000000 1.177000 ( 1.176000)
t:\jruby-1.3.1\bin\jruby.bat t:\benchmark.rb
1.409000 0.000000 1.409000 ( 1.305000)
1.218000 0.000000 1.218000 ( 1.217000)
1.210000 0.000000 1.210000 ( 1.209000)
1.181000 0.000000 1.181000 ( 1.181000)
1.191000 0.000000 1.191000 ( 1.191000)
c:\Programs\jruby-1.4\bin\jruby.exe t:\benchmark.rb
1.303000 0.000000 1.303000 ( 1.302000)
1.289000 0.000000 1.289000 ( 1.290000)
1.280000 0.000000 1.280000 ( 1.281000)
1.296000 0.000000 1.296000 ( 1.296000)
1.263000 0.000000 1.263000 ( 1.263000)
c:\Programs\jruby-1.4\bin\jruby.exe --1.9 t:\benchmark.rb
3.260000 0.000000 3.260000 ( 3.261000)
3.224000 0.000000 3.224000 ( 3.224000)
3.212000 0.000000 3.212000 ( 3.212000)
3.155000 0.000000 3.155000 ( 3.153000)
3.231000 0.000000 3.231000 ( 3.232000)