<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Java vs. C benchmark</title>
	<atom:link href="http://www.stefankrause.net/wp/?feed=rss2&#038;p=4" rel="self" type="application/rss+xml" />
	<link>http://www.stefankrause.net/wp/?p=4</link>
	<description>{ throw new NoFunnyProverbFoundException(); }</description>
	<lastBuildDate>Sun, 14 Mar 2010 20:07:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: bolovan</title>
		<link>http://www.stefankrause.net/wp/?p=4&#038;cpage=1#comment-206</link>
		<dc:creator>bolovan</dc:creator>
		<pubDate>Thu, 14 Jan 2010 14:54:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.stefankrause.net/wp/?p=4#comment-206</guid>
		<description>I looked on the code used for testing. The idea of a balancing test them and see how potent language or another. Therefore. Is around 60% faster to pass a pointer to a function than a variable. More, in your example, you pass a #define const as a parameter...why?
C/C++ can be very very slow if you write a bad code...but much more faster than allmost all high languages. And very close to asm language. I sow a lot of test that are writed in C++ in Java stile. Is like you drive an aricraft in car stile...is not working...</description>
		<content:encoded><![CDATA[<p>I looked on the code used for testing. The idea of a balancing test them and see how potent language or another. Therefore. Is around 60% faster to pass a pointer to a function than a variable. More, in your example, you pass a #define const as a parameter&#8230;why?<br />
C/C++ can be very very slow if you write a bad code&#8230;but much more faster than allmost all high languages. And very close to asm language. I sow a lot of test that are writed in C++ in Java stile. Is like you drive an aricraft in car stile&#8230;is not working&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason Smith</title>
		<link>http://www.stefankrause.net/wp/?p=4&#038;cpage=1#comment-187</link>
		<dc:creator>Jason Smith</dc:creator>
		<pubDate>Mon, 29 Dec 2008 01:53:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.stefankrause.net/wp/?p=4#comment-187</guid>
		<description>&quot;C/C++ is compiled, and optimised against the target CPU (if done properly)
Java is turned into bytecode and executed on a virtual machine.
There is no way that a java ‘program’ can be as fast unless the C/C++ coder has done something very stupid!&quot;

C/C++ is compiled - STATICALLY - against a range of CPUs.  Java bytecode is loaded at runtime, quickly JIT compiled, and then compiled dynamically as the program &quot;ages.&quot;  This means that Java code can not only be compiled against a very specific processor, but it can also optimise things like &quot;branch prediction,&quot; because it can watch the program run for a while before it optimally compiles the code.  This is why the &quot;-server&quot; JVM waits until a piece of code has been called at least 10,000 times (by default) before compiling it to machine code.

One of the main reasons that Java can be faster than C++ in real world applications is that malloc is a very slow way of managing memory.  Predictable, yes.  Fast, no.  Java, by default uses very fast, very low overhead allocation and collection algorithms.  Although C/C++ can allocate some memory on the stack, the heap portion kills it.  There are alternate memory management schemes for C/C++, and some of these are much faster than the default malloc.

The bottom line here is that with Java 6, the running code is very close in performance to C/C++.  With Java 6u10, the startup penalty has been significantly reduced.  I use some very heavyweight Java applications in my day-to-day work.  Eclipse (Java on SWT), Oxygen Author (Java Swing), and NetBeans (Java Swing), to name a few.  These are seriously complex applications that are quite usable.  

In my current work, we have an application that is composed of about 50 individual projects, and has to be customized at the code level for each of a dozen or so customers.  We&#039;d never be able to handle the kind of complexity we have without Java (or without a whole lot more very talented programmers).  Every time I have looked at integrating C/C++ code to speed things up, I have found that Java seems to be about the same speed.  Why add more complexity?  


&quot;I see no advantage to using java except maybe through pure laziness. With gcc, and sensible coding, it is possible to produce cross platform code relatively easily in C/C++.&quot;

Take a look at .NET.  Microsoft has put many billions behind this Java-like project.  There are significant advantages to be gained from the programming model used by Java.  But you would have to not be &quot;lazy,&quot; and actually go and study Java and/or .NET with an open mind.  :-)</description>
		<content:encoded><![CDATA[<p>&#8220;C/C++ is compiled, and optimised against the target CPU (if done properly)<br />
Java is turned into bytecode and executed on a virtual machine.<br />
There is no way that a java ‘program’ can be as fast unless the C/C++ coder has done something very stupid!&#8221;</p>
<p>C/C++ is compiled &#8211; STATICALLY &#8211; against a range of CPUs.  Java bytecode is loaded at runtime, quickly JIT compiled, and then compiled dynamically as the program &#8220;ages.&#8221;  This means that Java code can not only be compiled against a very specific processor, but it can also optimise things like &#8220;branch prediction,&#8221; because it can watch the program run for a while before it optimally compiles the code.  This is why the &#8220;-server&#8221; JVM waits until a piece of code has been called at least 10,000 times (by default) before compiling it to machine code.</p>
<p>One of the main reasons that Java can be faster than C++ in real world applications is that malloc is a very slow way of managing memory.  Predictable, yes.  Fast, no.  Java, by default uses very fast, very low overhead allocation and collection algorithms.  Although C/C++ can allocate some memory on the stack, the heap portion kills it.  There are alternate memory management schemes for C/C++, and some of these are much faster than the default malloc.</p>
<p>The bottom line here is that with Java 6, the running code is very close in performance to C/C++.  With Java 6u10, the startup penalty has been significantly reduced.  I use some very heavyweight Java applications in my day-to-day work.  Eclipse (Java on SWT), Oxygen Author (Java Swing), and NetBeans (Java Swing), to name a few.  These are seriously complex applications that are quite usable.  </p>
<p>In my current work, we have an application that is composed of about 50 individual projects, and has to be customized at the code level for each of a dozen or so customers.  We&#8217;d never be able to handle the kind of complexity we have without Java (or without a whole lot more very talented programmers).  Every time I have looked at integrating C/C++ code to speed things up, I have found that Java seems to be about the same speed.  Why add more complexity?  </p>
<p>&#8220;I see no advantage to using java except maybe through pure laziness. With gcc, and sensible coding, it is possible to produce cross platform code relatively easily in C/C++.&#8221;</p>
<p>Take a look at .NET.  Microsoft has put many billions behind this Java-like project.  There are significant advantages to be gained from the programming model used by Java.  But you would have to not be &#8220;lazy,&#8221; and actually go and study Java and/or .NET with an open mind.  <img src='http://www.stefankrause.net/wp/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rohan</title>
		<link>http://www.stefankrause.net/wp/?p=4&#038;cpage=1#comment-152</link>
		<dc:creator>Rohan</dc:creator>
		<pubDate>Fri, 04 Jul 2008 06:11:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.stefankrause.net/wp/?p=4#comment-152</guid>
		<description>It would be very interesting to look at D language test!</description>
		<content:encoded><![CDATA[<p>It would be very interesting to look at D language test!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonny</title>
		<link>http://www.stefankrause.net/wp/?p=4&#038;cpage=1#comment-127</link>
		<dc:creator>Jonny</dc:creator>
		<pubDate>Mon, 24 Mar 2008 13:33:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.stefankrause.net/wp/?p=4#comment-127</guid>
		<description>C/C++ is compiled, and optimised against the target CPU (if done properly)
Java is turned into bytecode and executed on a virtual machine.
There is no way that a java &#039;program&#039; can be as fast unless the C/C++ coder has done something very stupid!
I see no advantage to using java except maybe through pure laziness. With gcc, and sensible coding, it is possible to produce cross platform code relatively easily in C/C++.</description>
		<content:encoded><![CDATA[<p>C/C++ is compiled, and optimised against the target CPU (if done properly)<br />
Java is turned into bytecode and executed on a virtual machine.<br />
There is no way that a java &#8216;program&#8217; can be as fast unless the C/C++ coder has done something very stupid!<br />
I see no advantage to using java except maybe through pure laziness. With gcc, and sensible coding, it is possible to produce cross platform code relatively easily in C/C++.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brent</title>
		<link>http://www.stefankrause.net/wp/?p=4&#038;cpage=1#comment-42</link>
		<dc:creator>Brent</dc:creator>
		<pubDate>Thu, 29 Nov 2007 03:30:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.stefankrause.net/wp/?p=4#comment-42</guid>
		<description>&quot;One problem is that your not creating any garbage. All Real applications produce garbage. Java is slower than C when you have lots of objects.&quot;

Not true!

First, C does not have actual objects per se--things like strucs are much lighter weight, at the cost of being less useful than objects--so lets consider C++.

For apps that generate lots of objects, java is actually faster than C++ because java&#039;s automatic memory management is just so much better than what most people in most real applications can do by hand nowadays.

The main complaint from people who seriously look at languages is that java usually uses more memory than the equivalent C++ app (and both use more than if you wrote it in C).  Depending on the context (e.g. supercomputer versus tiny embedded device), this memory difference may/may not matter.

But memory intensive apps are a performance win for java.

Where C/C++ can still win over java is in certain numerical apps where hand tuned optimizations for certain cpus can make a difference.

The biggie is even jdk 6 still does not make great use of vector type of instructions; here are some links:
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6340864
    http://forum.java.sun.com/thread.jspa?threadID=5148725&amp;messageID=9564641
    http://forums.java.net/jive/thread.jspa?threadID=18675
This will undoubtably be rectified in the future, but for now it sometimes can be an issue.

But C/C++&#039;s days are numbered; the sweet spot of apps for where you really need C/C++ has and continues to shrink a lot to java&#039;s favor.  And java is so much more productive to program in, crossplatform, maintainable, etc.</description>
		<content:encoded><![CDATA[<p>&#8220;One problem is that your not creating any garbage. All Real applications produce garbage. Java is slower than C when you have lots of objects.&#8221;</p>
<p>Not true!</p>
<p>First, C does not have actual objects per se&#8211;things like strucs are much lighter weight, at the cost of being less useful than objects&#8211;so lets consider C++.</p>
<p>For apps that generate lots of objects, java is actually faster than C++ because java&#8217;s automatic memory management is just so much better than what most people in most real applications can do by hand nowadays.</p>
<p>The main complaint from people who seriously look at languages is that java usually uses more memory than the equivalent C++ app (and both use more than if you wrote it in C).  Depending on the context (e.g. supercomputer versus tiny embedded device), this memory difference may/may not matter.</p>
<p>But memory intensive apps are a performance win for java.</p>
<p>Where C/C++ can still win over java is in certain numerical apps where hand tuned optimizations for certain cpus can make a difference.</p>
<p>The biggie is even jdk 6 still does not make great use of vector type of instructions; here are some links:<br />
    <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6340864" rel="nofollow">http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6340864</a><br />
    <a href="http://forum.java.sun.com/thread.jspa?threadID=5148725&amp;messageID=9564641" rel="nofollow">http://forum.java.sun.com/thread.jspa?threadID=5148725&amp;messageID=9564641</a><br />
    <a href="http://forums.java.net/jive/thread.jspa?threadID=18675" rel="nofollow">http://forums.java.net/jive/thread.jspa?threadID=18675</a><br />
This will undoubtably be rectified in the future, but for now it sometimes can be an issue.</p>
<p>But C/C++&#8217;s days are numbered; the sweet spot of apps for where you really need C/C++ has and continues to shrink a lot to java&#8217;s favor.  And java is so much more productive to program in, crossplatform, maintainable, etc.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bevyn Quiding</title>
		<link>http://www.stefankrause.net/wp/?p=4&#038;cpage=1#comment-40</link>
		<dc:creator>Bevyn Quiding</dc:creator>
		<pubDate>Sun, 11 Nov 2007 21:44:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.stefankrause.net/wp/?p=4#comment-40</guid>
		<description>What i would like to see is a program compiled using 2003 compilers and run today.

I would expect C to be a bit quicker that java inherently.
But the advantage of bytecode on a vm is as the vm improves so does the byte-coded 
application.
That is not always the case for compiled applications.</description>
		<content:encoded><![CDATA[<p>What i would like to see is a program compiled using 2003 compilers and run today.</p>
<p>I would expect C to be a bit quicker that java inherently.<br />
But the advantage of bytecode on a vm is as the vm improves so does the byte-coded<br />
application.<br />
That is not always the case for compiled applications.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: woot</title>
		<link>http://www.stefankrause.net/wp/?p=4&#038;cpage=1#comment-38</link>
		<dc:creator>woot</dc:creator>
		<pubDate>Tue, 06 Nov 2007 05:54:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.stefankrause.net/wp/?p=4#comment-38</guid>
		<description>Your likely not reading comments this late in the game, but I wanted to ask for another implementation.  gcc-2.95.  Why would you benchmark this?  Well I&#039;ve read in multiple places that gcc has gotten progressively worse in performance with version increase.

For example a comp.lang.forth post giving this some credibility.
http://tinyurl.com/yvnh4t

Would be interesting if gcc-2.9.5 rocked ICC on any of the tests.</description>
		<content:encoded><![CDATA[<p>Your likely not reading comments this late in the game, but I wanted to ask for another implementation.  gcc-2.95.  Why would you benchmark this?  Well I&#8217;ve read in multiple places that gcc has gotten progressively worse in performance with version increase.</p>
<p>For example a comp.lang.forth post giving this some credibility.<br />
<a href="http://tinyurl.com/yvnh4t" rel="nofollow">http://tinyurl.com/yvnh4t</a></p>
<p>Would be interesting if gcc-2.9.5 rocked ICC on any of the tests.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: George</title>
		<link>http://www.stefankrause.net/wp/?p=4&#038;cpage=1#comment-37</link>
		<dc:creator>George</dc:creator>
		<pubDate>Tue, 06 Nov 2007 01:52:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.stefankrause.net/wp/?p=4#comment-37</guid>
		<description>One problem is that your not creating any garbage. All Real applications produce garbage. Java is slower than C when you have lots of objects.</description>
		<content:encoded><![CDATA[<p>One problem is that your not creating any garbage. All Real applications produce garbage. Java is slower than C when you have lots of objects.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Will</title>
		<link>http://www.stefankrause.net/wp/?p=4&#038;cpage=1#comment-36</link>
		<dc:creator>Will</dc:creator>
		<pubDate>Tue, 06 Nov 2007 00:30:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.stefankrause.net/wp/?p=4#comment-36</guid>
		<description>&quot;ICC is faster than GCC in every benchmark. This is not really new information and will surprise almost no one I guess.&quot;

Oh? I am surprised(though maybe not much since you are using a Core 2 Duo...). Here are my numbers for one of the benchmarks, with gcc 4.3 snapshot, and icc 10.0.023 on a P4.

fannkuch 11 runs:

icc -xN -O3 -ipo -static: 5.9s
gcc -O3 -march=pentium4 -funroll-loops -fomit-frame-pointer: 5.5s
gcc as above with profile-generate/profile-use: 5.0s</description>
		<content:encoded><![CDATA[<p>&#8220;ICC is faster than GCC in every benchmark. This is not really new information and will surprise almost no one I guess.&#8221;</p>
<p>Oh? I am surprised(though maybe not much since you are using a Core 2 Duo&#8230;). Here are my numbers for one of the benchmarks, with gcc 4.3 snapshot, and icc 10.0.023 on a P4.</p>
<p>fannkuch 11 runs:</p>
<p>icc -xN -O3 -ipo -static: 5.9s<br />
gcc -O3 -march=pentium4 -funroll-loops -fomit-frame-pointer: 5.5s<br />
gcc as above with profile-generate/profile-use: 5.0s</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://www.stefankrause.net/wp/?p=4&#038;cpage=1#comment-35</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Mon, 05 Nov 2007 21:42:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.stefankrause.net/wp/?p=4#comment-35</guid>
		<description>I can imagine easily than Xeons show a different behaviour than a core 2.
I&#039;ve checked it multiple times - your settings do not improve the results (I had to remove UseLargePages it printed a warning). There was no run that performed better than a plain java -server. But since all benchmarks create no new objects in their loops all GC and memory related settings shouldn&#039;t matter. As there&#039;s also no locking escape analysis and the locking flags don&#039;t help. How did you find exactly that set of arguments?

The results were:
3342 msec for java -server -XX:+AggressiveOpts -XX:+DoEscapeAnalysis -Xms128M -Xmx128M -XX:NewRatio=2 -XX:NewSize=64m -XX:CompileThreshold=1500 -XX:+UseThreadPriorities -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSParallelRemarkEnabled -XX:+CMSIncrementalMode -XX:+CMSIncrementalPacing -XX:ParallelGCThreads=4 -XX:MaxTenuringThreshold=2 -XX:SurvivorRatio=32 -XX:TargetSurvivorRatio=70 -XX:+UseTLAB -XX:MinTLABSize=4k -XX:TLABSize=256k -XX:+ResizeTLAB -XX:+UseBiasedLocking -XX:+UseSpinning -XX:PreBlockSpin=80 -XX:MaxInlineSize=200 -XX:FreqInlineSize=200 mandelbrot_long 4000 4001 4002 4003 4004 4005

3291 msec for java -server mandelbrot_long 4000 4001 4002 4003 4004 4005.

I also had to change the JRockit setting such that they work on my notebook (without a commercial JRockit license):
/home/stef/progs/jrockit-R27.3.1-jdk1.6.0_01/bin/java -server -Xms:128m -Xmx:128m -Xns:32m -XXaggressive:memory -Xgcprio:pausetime -XX:+UseNewHashFunction -XXallocPrefetch -XXcallProfiling -XXtlaSize:min=8k,preferred=512k -XXlazyUnlocking mandelbrot_long 4000 4001 4002 4003 4004 4005

The results were indistinguishable for your settings and just using -server and were about 3200 msec.</description>
		<content:encoded><![CDATA[<p>I can imagine easily than Xeons show a different behaviour than a core 2.<br />
I&#8217;ve checked it multiple times &#8211; your settings do not improve the results (I had to remove UseLargePages it printed a warning). There was no run that performed better than a plain java -server. But since all benchmarks create no new objects in their loops all GC and memory related settings shouldn&#8217;t matter. As there&#8217;s also no locking escape analysis and the locking flags don&#8217;t help. How did you find exactly that set of arguments?</p>
<p>The results were:<br />
3342 msec for java -server -XX:+AggressiveOpts -XX:+DoEscapeAnalysis -Xms128M -Xmx128M -XX:NewRatio=2 -XX:NewSize=64m -XX:CompileThreshold=1500 -XX:+UseThreadPriorities -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSParallelRemarkEnabled -XX:+CMSIncrementalMode -XX:+CMSIncrementalPacing -XX:ParallelGCThreads=4 -XX:MaxTenuringThreshold=2 -XX:SurvivorRatio=32 -XX:TargetSurvivorRatio=70 -XX:+UseTLAB -XX:MinTLABSize=4k -XX:TLABSize=256k -XX:+ResizeTLAB -XX:+UseBiasedLocking -XX:+UseSpinning -XX:PreBlockSpin=80 -XX:MaxInlineSize=200 -XX:FreqInlineSize=200 mandelbrot_long 4000 4001 4002 4003 4004 4005</p>
<p>3291 msec for java -server mandelbrot_long 4000 4001 4002 4003 4004 4005.</p>
<p>I also had to change the JRockit setting such that they work on my notebook (without a commercial JRockit license):<br />
/home/stef/progs/jrockit-R27.3.1-jdk1.6.0_01/bin/java -server -Xms:128m -Xmx:128m -Xns:32m -XXaggressive:memory -Xgcprio:pausetime -XX:+UseNewHashFunction -XXallocPrefetch -XXcallProfiling -XXtlaSize:min=8k,preferred=512k -XXlazyUnlocking mandelbrot_long 4000 4001 4002 4003 4004 4005</p>
<p>The results were indistinguishable for your settings and just using -server and were about 3200 msec.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
