From: Frank Mitchell Date: 2003-09-22T12:48:41+09:00 Subject: Re: Performance: Ruby vs Java This is a multi-part message in MIME format. --------------F1A8E2F9D9AA80235FA846E0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit BTW, just for comparison I translated your program into Python and Lua. (See www.python.org and www.lua.org, respectively.) Both languages compile their scripts into bytecodes before running them. On my pathetic 166 MHz laptop running Linux, calculating whether 400003 was prime took too long, so I knocked out a couple of zeroes. These are the timings I ended up with: prime.lua: 0:57.96 # Lua 5.0 prime.py: 3:23.01 # Python 2.2.2 prime.rb: 4:50.35 # Ruby 1.8.0 Prime.java 0:08.01 # Kaffe 1.0.7, JIT enabled So, even with Kaffe, the JIT makes one or two orders of magnitude difference. (The Lua number shows what a small and ultra-optimized interpreter could do.) Attached are the Python and Lua translations. -- Frank Mitchell (frankm each bayarea period net) Please avoid sending me Word or PowerPoint attachments. See http://www.fsf.org/philosophy/no-word-attachments.html --------------F1A8E2F9D9AA80235FA846E0 Content-Type: text/plain; charset=us-ascii; name="prime.py" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="prime.py" #!/usr/bin/env python def is_prime(n): for i in range(1, n): for j in range(1, n): if i * j == n: return 0 return 1 print is_prime(2) print is_prime(4) print is_prime(7) print is_prime(25) print is_prime(4003) # print is_prime(400003) --------------F1A8E2F9D9AA80235FA846E0 Content-Type: text/plain; charset=us-ascii; name="prime.lua" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="prime.lua" #!/usr/bin/env lua function is_prime(n) for i = 1, (n-1) do for j = 1, (n-1) do if (i * j) == n then return nil end end end return 1 end print(is_prime(2)) print(is_prime(4)) print(is_prime(7)) print(is_prime(25)) print(is_prime(4003)) -- print(is_prime(400003)) --------------F1A8E2F9D9AA80235FA846E0--