| By Jeremy Geelan | Article Rating: |
|
| June 15, 2004 12:00 AM EDT | Reads: |
217,777 |
Keith Lea writes of the benchmark, on his results page, "I was sick of hearing people say Java was slow, when I know it's pretty fast, so I took the benchmark code for C++ and Java from the now outdated Great Computer Language Shootout and ran the tests myself."
Lea used G++ (GCC) 3.3.1 20030930 (with glibc 2.3.2-98) for the C++, with the -O2 flag (for both i386 and i686). He compiled the Java code normally with the Sun Java 1.4.2_01 compiler, and ran it with the Sun 1.4.2_01 JVM. He ran the tests on Red Hat Linux 9 / Fedora Test1 with the 2.4.20-20.9 kernel on a T30 laptop. The laptop "has a Pentium 4 mobile chip, 512MB of memory, a sort of slow disk," he notes.
The results he got were that Java is significantly faster than optimized C++ in many cases.
"They also show that no one should ever run the client JVM when given the choice," Lea adds. ("Everyone has the choice," he says. To run the server VM, see instructions in the Using the Server JVM section below.)
JDJ has agreed to post online anyone else's results as long as they use Java 1.4.2 or higher and any version of GCC that produces faster or equivalent code than the 3.3.1 I used. We encourage you to download the source and/or the binaries and perform the tests yourself, with your favorite compiler and on your favorite platform.
Lea's Data and Results

- Data table and graph (also see above)
- Console run log
- Source:
- Binaries
- Download all source code and binaries: .bz2, (69KB) .zip (189KB)
JVM startup time was included in these results. "That means even with JVM startup time, Java is still faster than C++ in many of these tests," says Lea.
Some of the C++ tests would not compile. "I've never been very good at decoding GCC's error messages," he admits, "so if I couldn't fix a test with a trivial modification, I didn't include it in my benchmarks."
Lea also modified one of the tests, the string concatenation test for Java.
"The test was creating a new StringBuffer in each iteration of the loop, which was just silly," he explains. "I updated the code to use a single StringBuffer and appending to it inside the loop."
(The updated tests at the original shootout use this new method.)
"Java lost this benchmark even with the modifications," Lea declares. "So if anyone wants to accuse me of biasing the results, they're going to have to try harder."
Several versions of some of the C++ tests (like matrix) were present in the original shootout source, he continues.
"I used the versions without numbers in them, like matrix.g++ instead of matrix.g++2. I don't know which of these were used in the original benchmarks, but from my quick experimenting, the numberless ones generally ran faster than their numbered counterparts."
"Looking at them again," Lea says, "matrix.g++3 runs faster than the matrix.g++ that I use. However, it still runs slower than the Java version, so I don't plan to modify the graph/data unless someone asks me to, since getting that graph in the first place was sort of a pain.)"
He continues: "I've been told that the C++ code for the Method Call benchmark returns by value while the Java code returns by reference, and that modifying the C++ code to pass a pointer makes that benchmark faster. However, even with the modification, the C++ version still runs slower than the Java version."
Lea ran th Java and the C++ tests to "warm up" (both the Java and C++ tests got faster after he ran them a few times).
"I've been told that these tests are invalid because they were run with GCC," he concedes, adding: "I have seen both benchmarks that show GCC producing faster code than Visual Studio's VC++ compiler, and benchmarks showing the opposite. If I update the benchmarks with another compiler added, it will be the Intel C++ Compiler, which I'm pretty sure produces faster code than VC++."
Lea says he's been accused of biasing the results by using the -O2 option for GCC, "supposedly because -O2 optimizes for space, thus slowing down the benchmark," he explains.
But this is not what -O2 does, he points out, referring to the GCC -O documentation:
JVM startup time was included in these results. "That means even with JVM startup time, Java is still faster than C++ in many of these tests," says Lea.
Some of the C++ tests would not compile. "I've never been very good at decoding GCC's error messages," he admits, "so if I couldn't fix a test with a trivial modification, I didn't include it in my benchmarks."
Lea also modified one of the tests, the string concatenation test for Java.
"The test was creating a new StringBuffer in each iteration of the loop, which was just silly," he explains. "I updated the code to use a single StringBuffer and appending to it inside the loop."
(The updated tests at the original shootout use this new method.)
"Java lost this benchmark even with the modifications," Lea declares. "So if anyone wants to accuse me of biasing the results, they're going to have to try harder."
Several versions of some of the C++ tests (like matrix) were present in the original shootout source, he continues.
"I used the versions without numbers in them, like matrix.g++ instead of matrix.g++2. I don't know which of these were used in the original benchmarks, but from my quick experimenting, the numberless ones generally ran faster than their numbered counterparts."
"Looking at them again," Lea says, "matrix.g++3 runs faster than the matrix.g++ that I use. However, it still runs slower than the Java version, so I don't plan to modify the graph/data unless someone asks me to, since getting that graph in the first place was sort of a pain.)"
He continues: "I've been told that the C++ code for the Method Call benchmark returns by value while the Java code returns by reference, and that modifying the C++ code to pass a pointer makes that benchmark faster. However, even with the modification, the C++ version still runs slower than the Java version."
Lea ran the tests many times before running the "official" recorded set of tests, so there was plenty of time for both Java and the C++ tests to "warm up" (both the Java and C++ tests got faster after he ran them a few times).
"I've been told that these tests are invalid because they were run with GCC," he concedes, adding: "I have seen both benchmarks that show GCC producing faster code than Visual Studio's VC++ compiler, and benchmarks showing the opposite. If I update the benchmarks with another compiler added, it will be the Intel C++ Compiler, which I'm pretty sure produces faster code than VC++."
Lea says he's been accused of biasing the results by using the -O2 option for GCC, "supposedly because -O2 optimizes for space, thus slowing down the benchmark," he explains.
But this is not what -O2 does, he points out, referring to the GCC -O documentation:
-O2: Optimize even more. GCC performs nearly all supported optimizations that do not involve a space-speed tradeoff. The compiler does not perform loop unrolling or function inlining when you specify -O2. As compared to -O, this option increases both compilation time and the performance of the generated code.
"On the other hand, -O3 performs space-speed tradeoffs, and -O performs fewer optimizations. Thus, for these tests, I think O2 was the best choice," Lea concludes.
"I don't have an automated means of building and benchmarking these things (and the scripts that came with the original shootout didn't run for me)," he continues. "I really do want people to test it on their own machines, but it's going to take some work, I guess."
Lea compiled the C++ code with:
g++ [test].cpp -O2 -march=i386 -o [test]-386
g++ [test].cpp -O2 -march=i686 -o [test]-686
and the Java code with:
javac [test].java
To see how he ran the binaries, see the run log. You can download the source code he used in either .bz2 or .zip format.
Using the Server JVM
Every form of Sun's Java runtime comes with both the "client VM" and the "server VM."
"Unfortunately, Java applications and applets run by default in the client VM," Lea observes. "The Server VM is much faster than the Client VM, but it has the downside of taking around 10% longer to start up, and it uses more memory."
Lea explains the two ways to run Java applications with the server VM as follows
- When launching a Java application from the command line, use
java -server [arguments...]instead ofjava [arguments...]. For example, usejava -server -jar beanshell.jar. - Modify the
jvm.cfgfile in your Java installation. (It's a text file, so you can use Notepad or Emacs to edit it.) This is located in C:\Program Files\Java\j2reXXX\lib\i386\ on Windows, /usr/java/j2reXXX/lib/i386/ on Linux. You will see two lines:
You should change them to:-client KNOWN -server KNOWN
This change will cause the server VM to be run for all applications, unless they are run with the-server KNOWN -client KNOWN
-clientargument.
He can be contacted at
Every form of Sun's Java runtime comes with both the "client VM" and the "server VM."
"Unfortunately, Java applications and applets run by default in the client VM," Lea observes. "The Server VM is much faster than the Client VM, but it has the downside of taking around 10% longer to start up, and it uses more memory."
Lea explains the two ways to run Java applications with the server VM as follows
- When launching a Java application from the command line, use
java -server [arguments...]instead ofjava [arguments...]. For example, usejava -server -jar beanshell.jar. - Modify the
jvm.cfgfile in your Java installation. (It's a text file, so you can use Notepad or Emacs to edit it.) This is located in C:\Program Files\Java\j2reXXX\lib\i386\ on Windows, /usr/java/j2reXXX/lib/i386/ on Linux. You will see two lines:
You should change them to:-client KNOWN -server KNOWN
This change will cause the server VM to be run for all applications, unless they are run with the-server KNOWN -client KNOWN
-clientargument.
He can be contacted at keith@kano.net.
Links
- Java vs. C benchmark - the benchmark is in Microsoft Word format
- FreeTTS performance case study - at Sun Research
- Linux Number Crunching - used 1.4.1 VM, got very different results than Lea did, maybe due to floating point optimizations added in 1.4.2
- SNAP matrix benchmark - Java vs. C++ for matrix multiplication
- Nine-Language Performance Round-Up: math and file I/O performance among nine languages
- Performance comparison C++, C# and Java - similar results as Lea's, mostly
- Java vs. C - for bubble sort, IBM's 1.3.0 client JVM comes out on top over GCC with full optimizations
Published June 15, 2004 Reads 217,777
Copyright © 2004 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Jeremy Geelan
Jeremy Geelan is President & COO of Cloud Expo, Inc. and Conference Chair of the worldwide Cloud Expo series. He appears regularly at conferences and trade shows, speaking to technology audiences both in North America and overseas. He is executive producer and presenter of Cloud Expo's "Power Panels" on SYS-CON.TV.
![]() |
B Bennett 06/15/04 06:25:37 PM EDT | |||
Mr Salarian and people with similar questions should consult the methodology notes from the original shootout (whose code was borrowed for this test) at http://www.bagley.org/~doug/shootout/method.shtml That should help clarify what exactly is getting tested, and by what methods. |
||||
![]() |
A. Salarian 06/15/04 06:01:52 PM EDT | |||
Sir, with all due respect I have to say your benchmark is worthless. You have note compared a single C++ program to a Java program. The codes you have tested do not show anything. Why not some real world situation on WHY people use C++ but not Java? Like some complex matrix operations using template based libraries like Blitz++ and equivalent Java industry level Matrix libs? Some applications with a large number of dynamic allocations and deallocations like a dynamic patricia tri in a LZW implementaion? Why not largescale FFTs to test the efficiency of cache management? Why you didn''t use the instrumented C++ (i.e. using the profiling guided compilations)? |
||||
- Cloud People: A Who's Who of Cloud Computing
- Google Compute enters the IaaS market
- The Software Freedom Conservancy – Fundraising Campaign: Non-Profit Accounting Software
- Cloud Expo NY: Environmental Pressures Drive an Evolution in File Storage
- Cloud Expo NY: Interconnected Machines and the Future of Energy
- Cloud Conversations: AWS EBS, Glacier and S3 Overview | Part 3
- Cloud Business Solutions, Social Media, and Platform Systems of Engagement Market Shares, Strategies, and Forecasts, Worldwide, 2013 to 2019
- Healthcare Data on the Cloud – The Reality of Sensitive Information Online
- Google Submits Concessions to EC; Gets Sued in the UK
- Step-by-Step: Extend Your Network to the Cloud with Windows Azure Virtual Networks
- Cloud Expo New York | Storage & Archive: Are Existing Offerings Relevant?
- Shadow IT – The Reality Is Here
- Cloud People: A Who's Who of Cloud Computing
- Cloud Expo New York: How to Use Google Apps Script
- Apple Ordered to Pay VirnetX $333K a Day
- Google Compute enters the IaaS market
- The Software Freedom Conservancy – Fundraising Campaign: Non-Profit Accounting Software
- Cloud Expo NY: Environmental Pressures Drive an Evolution in File Storage
- Cloud Expo NY: Interconnected Machines and the Future of Energy
- Cavalry Rides into Oracle’s Java Suit
- Samsung Uses Centrify for Safer Android Platform
- Cloud Conversations: AWS EBS, Glacier and S3 Overview | Part 3
- Cloud Business Solutions, Social Media, and Platform Systems of Engagement Market Shares, Strategies, and Forecasts, Worldwide, 2013 to 2019
- Google Maps May Be Banned in Germany
- Where Are RIA Technologies Headed in 2008?
- Personal Branding Checklist
- The Top 250 Players in the Cloud Computing Ecosystem
- AJAXWorld 2006 West Power Panel with Google's Adam Bosworth
- Why Microsoft Loves Google's Android
- Google's OpenSocial: A Technical Overview and Critique
- Cloud People: A Who's Who of Cloud Computing
- Wal-Mart To Sell $399 Ubuntu Linux-based Laptop with Google Operating System
- Cloud Expo New York Call for Papers Now Open
- Dolphin Announces Open API With Over 50 Add-ons Including Dropbox and Wikipedia
- i-Technology Blog: Google Trends on Java, McNealy, AJAX, and SOA Give Pause For Thought
- i-Technology Blog: Is There Life Beyond Google?





























