From: Robert Klemme Date: 2004-09-15T17:34:54+09:00 Subject: Re: Groovy speeds ------=_NextPart_000_003C_01C49B0F.86C5A110 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit "Jim Weirich" schrieb im Newsbeitrag news:4146E923.2050601@weirichhouse.org... > > Not exactly but there is Groovy - if you need the looks of Ruby and the > > speed of Java. See http://groovy.codehaus.org/ > > I've seen several posts that hint that Groovy runs at Java-like speeds. > I haven't found this to be true at all. You can find one of my (very > incomplete and probably totally useless) benchmarks here: > http://onestepback.org/articles/groovy/groovyspeed.html That's interesting, although I think you didn't choose optimal implementations: 10:16:21 [source]: ruby /c/temp/ruby/fact-bm.rb Ruby: 54.1 MicroSeconds per call Ruby: 14.7 MicroSeconds per call Ruby: 13.5 MicroSeconds per call and 10:33:25 [groovy]: groovy fact.gr Groovy: 67.2 MicroSeconds per call Groovy: 59.4 MicroSeconds per call (HotSpot) Groovy: 57.9 MicroSeconds per call Groovy: 57.8 MicroSeconds per call (HotSpot) Groovy: 57.8 MicroSeconds per call Groovy: 57.8 MicroSeconds per call (HotSpot) Darn, I didn't expect groovy to be *that* slow. Kind regards robert ------=_NextPart_000_003C_01C49B0F.86C5A110 Content-Type: application/octet-stream; name="fact.rb" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="fact.rb" def fact1(n) n == 1 ? 1 : n*fact1(n-1) end def fact2(n) f = 1 for i in 1..n f *= i end f end require 'benchmark' include Benchmark N=700 bm do |x| x.report("recursive") do for n in 1..N fact1 n end end x.report("iterative") do for n in 1..N fact2 n end end end ------=_NextPart_000_003C_01C49B0F.86C5A110 Content-Type: application/octet-stream; name="fact.gr" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="fact.gr" REPEAT =3D 10000=0A= =0A= benchmark =3D { n, closure |=0A= start =3D System.currentTimeMillis()=0A= /* n.times { closure.call } */=0A= for ( i in 1 .. n ) { closure.call }=0A= delta =3D System.currentTimeMillis() - start=0A= ((float)delta) / n=0A= }=0A= =0A= def fact(n) {=0A= (2..n).inject(1) { f, i | f * i }=0A= }=0A= =0A= t =3D benchmark(REPEAT) { fact(10) }=0A= println "Groovy: ${1000*t} MicroSeconds per call"=0A= =0A= t =3D benchmark(REPEAT) { fact(10) }=0A= println "Groovy: ${1000*t} MicroSeconds per call (HotSpot)"=0A= =0A= def fact2(n) {=0A= f =3D 1=0A= for ( i in 2..n )=0A= f *=3D i=0A= end=0A= f=0A= }=0A= =0A= t =3D benchmark(REPEAT) { fact2(10) }=0A= println "Groovy: ${1000*t} MicroSeconds per call"=0A= =0A= t =3D benchmark(REPEAT) { fact2(10) }=0A= println "Groovy: ${1000*t} MicroSeconds per call (HotSpot)"=0A= =0A= def fact3(n) {=0A= f =3D n=0A= while ( n !=3D 1 ) {=0A= f *=3D (n -=3D 1)=0A= }=0A= f=0A= }=0A= =0A= t =3D benchmark(REPEAT) { fact3(10) }=0A= println "Groovy: ${1000*t} MicroSeconds per call"=0A= =0A= t =3D benchmark(REPEAT) { fact3(10) }=0A= println "Groovy: ${1000*t} MicroSeconds per call (HotSpot)"=0A= ------=_NextPart_000_003C_01C49B0F.86C5A110--