Java speed vs. C++.  
Author Message
jarrodhroberson





PostPosted: 2004-12-8 4:59:00 Top

java-programmer, Java speed vs. C++. Mike Cox wrote:
> 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.println("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.

first explain how your super contrived hello world example has any
RELEVANCE what so ever to Apache, Jakarta or anything thing else server
related?

If you are not a troll, then your least worry is the speed of running a
contrived hello world example, it is more like getting much more basic
fundemental understanding about practical programming.
if you are just trolling just stop.

 
jarrodhroberson





PostPosted: 2004-12-8 4:59:00 Top

java-programmer >> Java speed vs. C++. Mike Cox wrote:
> 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.println("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.

first explain how your super contrived hello world example has any
RELEVANCE what so ever to Apache, Jakarta or anything thing else server
related?

If you are not a troll, then your least worry is the speed of running a
contrived hello world example, it is more like getting much more basic
fundemental understanding about practical programming.
if you are just trolling just stop.

 
jarrodhroberson





PostPosted: 2004-12-8 4:59:00 Top

java-programmer >> Java speed vs. C++. Mike Cox wrote:
> 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.println("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.

first explain how your super contrived hello world example has any
RELEVANCE what so ever to Apache, Jakarta or anything thing else server
related?

If you are not a troll, then your least worry is the speed of running a
contrived hello world example, it is more like getting much more basic
fundemental understanding about practical programming.
if you are just trolling just stop.

 
 
James Kanze





PostPosted: 2004-12-9 4:57:00 Top

java-programmer >> Java speed vs. C++. email***@***.com wrote:

> first explain how your super contrived hello world example has any
> RELEVANCE what so ever to Apache, Jakarta or anything thing else server
> related?

Actually, if he is counting on using Java to implement CGI scripts, he's
found one of the few application areas where it is relevant. (Of
course, one could question the reasonableness of such a choice, given
the presence of JSP.)

> If you are not a troll, then your least worry is the speed of running a
> contrived hello world example, it is more like getting much more basic
> fundemental understanding about practical programming.
> if you are just trolling just stop.

There are applications where start-up time is important. I have a
couple of small programs that I invoke from the editor to filter part of
the text -- typically just a couple of lines; JDK's start up time pretty
much makes Java a no runner here. There are other applications where it
isn't, but other things in Java implementations make the language
inappropriate. And of course, there are other applications for which it
is really the only reasonable alternative -- I'm certainly not going to
write CGI code in *any* language if I can use JSP.

For most large scale applications, of course, the performance of the
language simply isn't an issue these days.

--
James Kanze home: www.gabi-soft.fr
Conseils en informatique orient閑 objet/
Beratung in objektorientierter Datenverarbeitung
9 pl. Pierre S閙ard, 78210 St.-Cyr-l'蒫ole, France +33 (0)1 30 23 00 34
 
 
Piotr Plazienski





PostPosted: 2004-12-9 16:25:00 Top

java-programmer >> Java speed vs. C++. Joona I Palaste wrote:

> Dan Elliott <email***@***.com> scribbled the following
> on comp.lang.java.programmer:
>
>>"Mike Cox" <email***@***.com> wrote in message
>>news:email***@***.com...
>>
>>>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.println("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.