From: Lars Christensen Date: 2002-05-06T16:15:59+09:00 Subject: Re: Ruby vs. Java vs. Native trivia On Sat, 4 May 2002, Sean Russell wrote: > Hi, > > I'm reposting this, because I don't think it got propegated properly the > first time. I can't find the post on Google, anyway. > > > I thought I'd post these results to the list, since you might find them > interesting. This really is unscientific trivia, so digest it as such. > > I've been playing with GCJ, the Java-to-native compiler. I've got this > little application called EDT that does some basic math and generates a > decimal-based time from the current time. I've written it in both Ruby and > Java, and have been using it to get familiar with GCJ. I did some timing > tests, just to see how things behaved, and the results are more or less > surprising. > > The important thing to note is that this is a VERY small app, so startup > delays are disproportionately weighted. However, this doesn't invalidate > the tests; I have a number of little apps like this that I run multiple > times daily, and the startup times do indeed impact the "user enjoyment" > factor. > > These are from an average of five runs, using Linux's 'time'. edt_java is > pure java, using the 1.4 vm; edt is the ruby version, and EDT is the > java-compiled-to-native version: > > TIMES (USER) > ./edt_java: 1.27 > ./EDT: 0.14 > edt: 0.11 > CPUS (%) > ./edt_java: 64.33 > ./EDT: 56.33 > edt: 74.67 > TOTALS (TIME) > ./edt_java: 2.22 > ./EDT: 0.33 > edt: 0.18 For a numerical-intensive program i'm getting QUITE a different result. I took the "Sieve of Eratosthenes" Benchmark from The Great Computer Language Shootout page ran an it with ruby, jdk-1.4 and gjc-3.0.4. Here are the results: # Ruby-1.6.7 (shared) $ time ruby sieve.ruby 5000 Count: 1028 user 1m47.470s # Ruby-1.7.2 (2002/05/06) (shared) $ LD_LIBRARY_PATH=. time ./ruby ~/bench/sieve.ruby 5000 Count: 1028 user 2m43.800s # j2se-1.4 $ time java sieve 5000 Count: 1028 user 0m1.420s # gcj-3.0.4 $ time ./sieve 5000 Count: 1028 user 0m2.440s The Ruby Benchmark isn't all fair, because i'm using a dynamically linked version of Ruby, which, by my benchmarks, are 30-40% slower than a statically linked (Can anyone explain this?). It doesn't change the conclusion though: Ruby is (more than relatively) slow for things like this. This on Intel Solaris 2.8. -- Lars Christensen, larsch@cs.auc.dk