Message from discussion
Optimise my ray tracer
Path: g2news1.google.com!news4.google.com!news.glorb.com!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!zen.net.uk!dedekind.zen.co.uk!nntp-peering.plus.net!ptn-nntp-feeder03.plus.net!ptn-nntp-spool02.plus.net!ptn-nntp-reader03.plus.net!not-for-mail
Message-Id: <42aa36e9$0$41924$ed2619ec@ptn-nntp-reader03.plus.net>
From: Jon Harrop <use...@jdh30.plus.com>
Subject: Re: Optimise my ray tracer
Newsgroups: comp.lang.java.programmer
Date: Sat, 11 Jun 2005 01:56:16 +0100
References: <429e5795$0$7560$ed2619ec@ptn-nntp-reader03.plus.net> <9c838fb.0506021056.7fdfc1be@posting.google.com> <1118360978.847065.245350@g47g2000cwa.googlegroups.com> <42aa2272$0$41906$ed2619ec@ptn-nntp-reader03.plus.net> <MPG.1d13d8f7a4c7274c9899ff@news.altopia.net>
Organization: Flying Frog Consultancy Ltd.
User-Agent: KNode/0.8.2
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7Bit
Lines: 74
NNTP-Posting-Host: 1f041d46.ptn-nntp-reader03.plus.net
X-Trace: DXC=^3d8UR6;AK^37DAj2W^2]]igd3Y`7Rb;^@`8gV4CC7IW1?KeQZ3XN3U7_?RLP86fmR5PCcS[NJ6<[lEg;^I:aFL^
X-Complaints-To: abuse@plus.net
Chris Smith wrote:
> Jon Harrop <use...@jdh30.plus.com> wrote:
>> Can you elaborate on this? All of my tests indicate that Java is many
>> times slower than most other modern languages, even stereotypically slow
>> languages like SML and OCaml.
>
> You're making statements that are far too broad to be useful. Java is
> far slower doing what?
Running my ray tracer.
> Most computational tasks tend to run within about 10% to 20% of optimal
> time for the hardware platform, and compare about evenly with modern
> compiled languages.
If you're trying to say that equivalent programs written in different
languages like C, C++, Java, SML, OCaml and Fortran will be within 20% of
each other's performance then that definitely isn't true. Any programs
which stress allocation/deallocation (e.g. balanced binary trees) are
likely to do significantly worse in garbage collected languages. Any
programs which stress indirected data structures will do significantly
worse in OCaml, particularly when pointers cost 64 bits.
> There are specific tasks for which significant
> general performance differences may be measured (floating point
> calculations being one, but I can't recall whether Java is typically
> faster or slower here, and it may depend on the platform), but this
> wouldn't be described as "many times slower".
Here are the times for running my ray tracer on x86 (1.2GHz Athlon T-bird)
with n=128, level=6 and ss=4:
Mlton 1.250s mlton ray.sml
IFC 1.361s ifort -O3 -u -static-libcxa -o raytracer raytracer.f90
C++ 1.555s g++-3.4 -O3 -march=athlon-tbird -ffast-math ray.cpp -o ray
ocamlopt 1.932s ocamlopt -inline 100 ray.ml -o ray
SML-NJ 2.085s sml ray.sml
G95 3.351s g95 -O3 -ffast-math ray.f90 -o ray
C 4.125s gcc-3.4 -lm -std=c99 -O3 -march=athlon-tbird
-funroll-all-loops -ffast-math ray.c -o ray
Java 6.492s javac ray.java
GCJ 20.316s gcj-3.4 --main=ray -Wall -O3 -march=athlon-tbird
-funroll-all-loops -ffast-math ray.java -o ray
ocamlc 41.047s ocamlc ray.ml -o ray
as you can see, Java run under Sun's J2SE is over 5x slower than the fastest
implementation (Mlton-compiled SML).
> I strongly suspect that the issue is startup time.
I have taken many measurements for different running times (<2s to >20s)
and, assuming Java's startup time to be constant, the startup time is
insignificant.
> If you're measuring
> it with your ray tracer, are you measuring externally so as to include
> the startup time, or internally once the VM has started? There's no
> "right" way to do this; it depends on whether your target audience will
> care about startup time, or only how the appo performs once it's
> running. However, if you're including startup time, you ought to at
> least add a note that this is the reason for the results. The great
> majority of applications run for orders of magnitude longer than the
> average benchmark, and just saying that Java is slower is very
> misleading.
Right, well I've accounted for that and I can still only conclude that Java
is very slow.
I've also run the ray tracer on AMD64 with JDK 1.5 and Java is still
significantly slower than other languages, albeit "only" 2.4 times slower.
--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com