Joona I Palaste wrote:
Dan Elliott <da************ ************@no spam.org> scribbled the following
on comp.lang.java. programmer:
"Mike Cox" <mi**********@y ahoo.com> wrote in message
news:31****** *******@individ ual.net...
Hi. I recently ran a benchmark against two simple programs, one written
in
Java and the other in C++. The both accomplish the same thing, outputting
"Hello World" on my screen. The C++ program took .5 seconds to complete
on
my 400 Mhz PC while the Java program took 6.5 seconds.
I am running the SUSE 8.2 Linux distribution.
Why is Java that much slower than the C++ program? I read on Slashdot
that
Java was almost as fast as C++. Here are my programs:
test.cpp
#include <iostream>
using namespace std;
int main()
{
cout<<"Hello World";
}
test.java
public class test
{
public static void main(String[] args)
{
System.out.prin tln("Hello world");
}
}
The reason I ask is because I'm thinking of using Apache and Jakarta to do
some development. If Java cannot be speeded up, I will be forced to find
another alternative.
Mike,
This is a truly pathetic test. I am not sure you could learn ANYTHING of
value from it.
I agree. The overhead of starting the Java process and creating a VM is
way too large in this test. Try to print "Hello world" one million times
in a loop for a fairer test.
Actually that wont't do either. Console has its limits, and outputting
anything at that rate makes everything slow down to console speed. My
brother 'proved' that perl is working at same speed as c that way.
Better (but also silly) is to do loop that outputs something, does
something without ouputting, disk usage and so on (like
incrementing/decrementing or modulo-ing variable) and does it many
times, then execute that loop many more times :D.
I mean sometning like that:
#include <iostream>
using namespace std;
int main()
{
for(i=0; i<many_times;i+ +)
{
cout<<"Hello World";
for(j=0;j<many_ many_times;j++)
{
i++;
i--;
}
}
}
and you have to take many_many_times high enough to slow doen output to
maybe one "hello" a second, and many many_times to take program to
execute not less than i think 30 secs to reduce impact of preparing a
program.