my crude benchmark results
Andrew Haley
aph@redhat.com
Tue Jul 13 10:07:00 GMT 2004
John Gabriele writes:
> A friend was just asking me about speed when using Java
> for trig, so I put together a small program to get some
> *very* crude benchmark results. See the end of this email
> for the source code text. It's in C as well as Java. I'm on
> Mac OS X at the moment (a 500 MHz G3 with 256 MB),
> and I compared the C program with Apple's JVM as well as
> with GCJ 3.4.0.
>
> I realize that such a contrived program can't possibly
> give results that are scalable to large production software,
> and further, that developer time for said large program
> is likely far less than for a similar C or C++ program. However,
> here are my results anyway (in case they might be of any
> interest to anyone here).
>
> I ran each program multiple times in a row (without touching
> the rest of the operating system) and got a nice average for
> each. Ok,.. heaven forgive me for the cycles I am about to burn...
>
> Time taken to run:
>
> in C:
> 8.5 seconds
>
> Java via Apple's JVM:
> 22.2 seconds
>
> Java via GCJ:
> 25.5 seconds
>
> Of course, considering that GCJ is Free software, and the large
> number of platforms it runs on, I'm quite happy with it. Still though,
> it's surprising how much faster C is than Java for this simple
> procedural code.
>
> Though, as an aside, I should mention that I'm absolutely blown away
> at how blindingly fast computers are these days in general (taking
> sines,
> cosines, arcsines, arccosines, and squares of 50000 doubles, done 100
> times, in under half a minute. *Yow* that's friggin fast. Whew! [wipes
> sweat off forehead]).
>
> Do you folks on GNU/Linux and MS Windows get about the same sort
> of ratios?
gcj has its own math library that is very accurate but doesn't use the
FPU's builtins. Turn that off with -ffast-math.
$ gcc main.c -O3 -lm -ffast-math
$ time ./a.out
Size = 50000
Sum = 50000.000000
2.81user 0.01system 0:02.83elapsed 99%CPU
$ gcj Main.java --main=Main -O3 -ffast-math
$ time ./a.out
Size = 50000
Sum = 50000.0
3.53user 0.03system 0:04.19elapsed 84%CPU
Java is slighty slower, probably because of bounds checks and
synchronization.
Trying without bounds checks, to be a more accurate comparison with C:
$ gcj Main.java --main=Main -O3 -save-temps -ffast-math -fno-bounds-check
$ LD_LIBRARY_PATH=/usr/local/lib time ./a.out
Size = 50000
Sum = 50000.0
3.42user 0.03system 0:03.48elapsed 98%CPU
21% slower. I can live with that.
Andrew.
More information about the Java
mailing list