# Java is 40 times slower than C

L. Van Warren (lvwarren@wdv.com)
Sat, 24 May 1997 14:19:10 -0500

- Messages sorted by: [ date ][ thread ][ subject ][ author ]
- Next message: Radu Nicolescu: "Re: Frequently Asked Questions - Applet Security"
- Previous message: Xiao, Kevin: "Java Security"

    Date: Sat, 24 May 1997 14:19:10 -0500

    From: "L. Van Warren" <lvwarren@wdv.com>

    To: jdk-comments@web2.javasoft.com, java-security@web2.javasoft.com,

    Subject: Java is 40 times slower than C

Well -

I had been porting my code libraries to Java in the hope of making
them platform independent, pointerless, and object oriented. I have
been reusing some of this software since 1983. Why not transform
everything into the most modern Java form, a well-layered onion, a final
port for the year 2000, one last change before discarding all that awful
'C'?

I started the project by building a visual environment that would
present the results from the battery of tests in an aesthetic way.
A perfect simulation of green engineering graph paper complete with
holes and printability and a menu for selecting classes and test runs.
*whew*

This Saturday morning, for my birthday, I got the results from my
carefully controlled numerical experiment comparing the speed of 'C'
code to Java on my 120 MHz PowerPC using Metrowerks CW 11.

The bottom line is that Java is 40 times slower than C.

Bread and butter operations like:

c = addVec(a, b); /* C */

run 40 times slower in clean Java, i.e.

c = a.add(b); // Java

Now maybe you don't use such operations, or need them to be platform
independent. Most of the engineering and scientific computing that I
requires grinding numbers, especially vectors.
Even most games and simulations require that. Have you seen any
sophisticated games or simulations on the net in Java? I haven't. Now
I know why...

Using esoteric tricks like optimizing and making the class "final" as
in "Math" did speed things up a little. I did some awful things and
sped it up so it was ONLY 20 times slower. But, I would never use THAT
code.

I had heard that Java was an order of magnitude slower,
but I didn't believe it. I thought, "I can make it go faster, I am
good".

Consider some car A that ran 40 times slower than car B.
Would you use it?
A goes 80 mph on the freeway. How fast does B go?
B goes 2 mph. B doesn't get on the street, much less the freeway.
I can crawl on my face at 2 mph.

Consider an airplane A that ran 40 times slower than airplane B.
400 mph for A equals a 10 mph jog for B.
Would you jog from LA to New York,
every time you had to run an errand?

Thought you might find this result interesting. My head is swimming.
My whole approach is devastated. I am going spend the rest of my
birthday considering other careers...

- Van

- Next message: Radu Nicolescu: "Re: Frequently Asked Questions - Applet Security"
- Previous message: Xiao, Kevin: "Java Security"