From: kroeger@... (Malte Finsterwalder) Date: 2002-05-05T20:52:26+09:00 Subject: Re: Ruby vs. Java vs. Native trivia On 4 May 2002 07:19:10 -0700, Sean Russell wrote: I don't know anything about GCJ. But I was wondering how much baggage it carries in terms of Garbage collector and runtime environment etc. Especially for small and short running apps this can generate quite some overhead. That would to some degree explain your results. Ruby starts fast and has rather low baggage. Greetings, Malte >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 > >TIMES: The pure java JIT doesn't get a chance to kick in on this app because >it is so small; this is why the values reflect the pure Java version being >ten times as slow as the native. > >TOTALS: It also comes as no surprise the pure java takes nearly 7 times as >long as the native compiled version; that's the Java VM penalty for you. > >CPU: I'm also not surprised that the native version uses the least amount of >CPU; there's no interpretation going on. > >The big surprise here is that Ruby is so fast. It is not only interpreted, >but is text-based, not bytecode. Despite this, it is almost as fast as the >native code. It uses the most CPU -- that's the interpretation -- and if >you normalize the CPU usage, the Ruby version is just a little slower than >the native version, having a run TIME of 0.18s and a TOTAL time of 0.44. >The app feels snappier because of the additional CPU usage -- I'm not >sure why Linux decides that the Ruby version deserves more processing >power. > >Still, this is pretty amazing. I expected the Java "native" version to do >much better than the Ruby version. I suspect that this is because there's >significant overhead in the native version that wouldn't be there if I had >hand-crafted the native version from C or ASM. > >One last point: the sizes are significantly different as well. The Ruby >version is 2.6Kb large; the native Java version is 126Kb large, AND is >dynamically linked to a number of libraries. I haven't calculated how >large the minimum run environment is (Ruby interpreter+code vs. GCJ >libs+code). > >--- SER