473,767 Members | 2,226 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Java speed vs. C++.

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.


Jul 22 '05
30 2818
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.
Jul 22 '05 #31

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

73
8069
by: RobertMaas | last post by:
After many years of using LISP, I'm taking a class in Java and finding the two roughly comparable in some ways and very different in other ways. Each has a decent size library of useful utilities as a standard portable part of the core language, the LISP package, and the java.lang package, respectively. Both have big integers, although only LISP has rationals as far as I can tell. Because CL supports keyword arguments, it has a wider range...
6
5950
by: John Smith | last post by:
Hello, I have a rather odd question. My company is an all java/oracle shop. We do everything is Java... no matter what it is... parsing of text files, messaging, gui you name it. My question is this... is Perl so much better at parsing text files and outputing that we would see a substantial speed increase? We process about 10 million records in flat files a day for reformatting before putting them in a DB. Also, when it comes to...
4
5305
by: Arich Chanachai | last post by:
What are the pros and cons of Java? How does Java measure up to .NET in terms of speed? How about in terms of depth of classes? I am looking for garbage collection while at the same looking for speed. Java and .NET seem to be the only two application platforms offering both, any suggestions? Thanks all!!
114
9880
by: Maurice LING | last post by:
This may be a dumb thing to ask, but besides the penalty for dynamic typing, is there any other real reasons that Python is slower than Java? maurice
11
9269
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in C++. I find my self sometimes, trying Object app = Object(); Object *app = Object(); Object app = new Object();
19
3202
by: Davey | last post by:
Which is typically faster - a Java server application or a C++ server application?
6
13576
by: mearvk | last post by:
Does C++ or C have something roughly equivalent to this: http://java.sun.com/javase/6/docs/api/java/math/BigInteger.html What I need is a way to quickly convert between decimal and binary and from char*/string to a numeric representation. Thanks!
29
2350
by: s0suk3 | last post by:
Hello, I was hoping to get some opinions on a subject. I've been programming Python for almost two years now. Recently I learned Perl, but frankly I'm not very comfortable with it. Now I want to move on two either Java or C++, but I'm not sure which. Which one do you think is a softer transition for a Python programmer? Which one do you think will educate me the best?
7
3660
by: Sanny | last post by:
I have an app in Java. It works fine. Some people say Java works as fast as C. Is that true? C can use assembly language programs. How much faster are they inplace of calling general routines. Can C++ directly acess the Registers. Will the Computation 5-10 times faster than Java?
0
9404
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10168
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9838
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8835
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6651
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.