Talk:Java performance: Difference between revisions

Content deleted Content added
No edit summary
syntaxhighlight & fix lint
 
(48 intermediate revisions by 26 users not shown)
Line 1:
{{WikiProject Javabanner shell|class=stubB|importance=low}}
{{WikiProject Computing|class=Java |importance=mid}}
{{WikiProject Software |importance=mid}}
}}
{{Broken anchors|links=
* <nowiki>[[Metadata#Program metadata|metadata]]</nowiki>
}}
 
== "x times slower" ==
Line 8 ⟶ 13:
 
Even if "Foo is X times slower than Bar" is technically correct, it's easier for readers to understand "Bar is X times faster than Foo" or "Foo is an Xth as fast as Bar". --[[Special:Contributions/70.41.70.6|70.41.70.6]] ([[User talk:70.41.70.6|talk]]) 05:28, 22 October 2010 (UTC)
 
It's not, because the expression "4 times slower than Y" is meaningless. "One times slower than Y" means "0% of Y". What on earth is "four times slower that Y"? It is better to say "25% the performance of Y". 40km/h is definitely not "2 times slower than 80km/h" as "2 times slower than 80km/h" is -160km/h. Or in your world is "2 times faster than 80km/h" the same as "120km/h"? :-)
[[User:Kelt65|Kelt65]] ([[User talk:Kelt65|talk]]) 00:04, 20 October 2016 (UTC)
 
== Comparing C++ and Java is not that easy ==
Line 28 ⟶ 36:
 
==Program Speed ==
Surely we need more references or benchmarks to support the claim "Java's speed is now comparable with C or C++ and in some cases Java is significantly faster". I am a professional programmer who works with both Java and C/C++ and in my experience, everything done in Java is MUCH slower. At the moment there is only a very questionable benchmark as a reference, which uses a 3D engine. This is a bad example, as the drivers/OpenGL api implementation would have more of an influence on the FPS than the actual language used. [[Userhttps:CptAnonymous|CptAnonymous]//acadgild.com Acadgild] 14:47, 8 September 2007 (UTC)
:I added the Jake example, but then I wrote: ''Java programs take more time to start, are slower and use more memory than their C or C++ equivalents.'' But I don't completely agree with you: OK Java is slower than C/C++, but not MUCH slower; and I think that the Jake example is relevant (but I agree that it is not a benchmark). 3D engines typically create a LOT of objects (outside the OpenGL API), and they need to update frames every few milliseconds. OK, the OpenGL driver performance is very important, but after that, the 3D engine used on top of it, and the game itself, are also important. Badly coded (or unfinished) video games typically lag (see Stalker, for example), regardless of the driver. [[User:Hervegirod|Hervegirod]] 22:05, 8 September 2007 (UTC)
:: I use C/C++ for real works (used to it + more portable), however if to think for desktop then my impression is that the java as language is also good looking, often easier to write than C++ and very quick language. Articles about "java perfomance" in wikipedia can no way raise the speed of the programs you write. What makes the real applications in java commonly slow is probably the widespread programming style. Feels like java developers do not often concentrate on solving the real problems of their users quickly and simplily and elegantly. Java developers seemingly concentrate (as first thing) on the modularity of software and the engineering process and feature-richness of their classes and modules (also important and welcome). However when one forgets for what he does it all ... it may result with perfect-looking foam factories (just a waste of power). java engines now optimize the bloat out runtime. Adjusting things with such a powerful engines drags down the starting and loading performance. So like usual ... the problems may lay between the chair and keyboard. Vambola Kotkas [[Special:Contributions/212.47.207.152|212.47.207.152]] ([[User talk:212.47.207.152|talk]]) 13:58, 4 February 2008 (UTC)
Line 52 ⟶ 60:
While Java may be able to do escape analysis more often than C++, it can be used sometimes in C++. For example the following code:
 
<syntaxhighlight lang="text">
<code>
class Bar {
int inc(int i) { return i + 1 }
Line 62 ⟶ 70:
delete b;
}
</syntaxhighlight>
</code>
 
with this code the compiler can know, that b will never be used outside of the function foo. I agree that pointers make escape analysis harder, but under certain conditions the compiler can verify that varibles do not escape a funciton. BTW, I have not programmed in C++ in a long time. Thus I may have made some syntactic errors.
Line 71 ⟶ 79:
[[User:213.237.48.86|213.237.48.86]] 19:21, 11 October 2007 (UTC)
: "the compiler != the compiler". Java is compiled twice. Generics and there cast are added by the javac complier. The JIT-Complier may produce different code. In the case of generics hints are added for the runtime, which can be used to optimize the code. However you can't guarantee type-saftie as you can cast any Collection to a generic collection and add different types of Objects. Java7 or Java8 will propably address it by introducing generic types into the jvm itself. --[[Special:Contributions/141.84.69.20|141.84.69.20]] ([[User talk:141.84.69.20|talk]]) 17:37, 5 May 2008 (UTC)
 
{{reflist-talk}}
 
==Program Speed 2==
Line 104 ⟶ 114:
 
This page is now close to being neutral. I think we should move some of content into [[Comparison of Java and C++]], because there is much duplication. [[User:Alliumnsk|Alliumnsk]] ([[User talk:Alliumnsk|talk]]) 04:14, 30 August 2010 (UTC)
 
The way to use [http://www.bytonic.de/html/benchmarks.html| the page that note 42 refers to] to describe that Java is faster than C in some cases is clearly cheat! The only one listed in that page that Java is faster than C is the 240 vs 260/250 fps one -- the Original C Code vs Jake2-0.9.4 JRE1.5 fastjogl/lwjgl. The speed of programs that using OpenGL is largely depended on OpenGL. Is OpenGL vs fastjogl (FAST java OpenGL) objective? It is just like to compare two codes which runs on [[Intel 8086|86]] and [[Intel_Core#Core_i7_5|i7]] and says that the program that runs on i7 is faster. [[User:Jacob grace|Jacob grace]] ([[User talk:Jacob grace|talk]]) 22:06, 28 September 2015 (UTC)
 
== A controversial paragraph ==
Line 203 ⟶ 215:
: There are two reasons why Java JIT compiler can rearrange calls to foo and bar, first is because there are no pointers in java, making it easier for the compiler to prove that the reordering (or inlining) will not change anything, second is because of deoptimization, the JIT compiler can make aggressive optimizations based on assumptions (not proof), and deoptimize the code (un-JIT it) if it appear over the time that its assumptions were not true anymore. Concerning your Apple / Fruit example, arrays are objects not pointers in Java, so you are not allowed to put something which is not an Apple in an Apple array. In C/C++, you can put anything in it since an array is just a pointer. [[User:Hervegirod|Hervegirod]] ([[User talk:Hervegirod|talk]]) 17:18, 23 October 2011 (UTC)
:: In this example, it cannot be 'easier' because cost of this for C/C++ is zero. Aggressive (dangerous) optimizations, again, involve run-time check. "No pointers" is more a naming issue. In C, if you have struct complex { float re,im; }; and never take addresses of its fields - re and im (why would you?), but only take addresses of struct complex - you get the same "no pointers" situation as in Java. You miss the Apple/Fruit example entirely. Java disallows this only at run-time, inserting dynamic type-checks. C++ disallows at compile-time. Well you can still put a Pear in Apple array (do you even know how? a simple typecast won't work), but it violates the rules. For one thing you can be sure, there will be no dynamic check for that just because compiler wasn't clever enough to prove it is not necessary.
<sourcesyntaxhighlight lang="java">
class aa {
static class Fruit{}
Line 214 ⟶ 226:
}
}
</syntaxhighlight>
</source>
[[User:Alliumnsk|Alliumnsk]] ([[User talk:Alliumnsk|talk]])
:: The fact that Java hides pointer semantics from the programmer means nothing about the underlying architecture. Actually, ''every'' object in Java is a pointer, wrapped in a shiny name "reference", except for the primitives.[[User:1exec1|1exec1]] ([[User talk:1exec1|talk]]) 23:08, 25 October 2011 (UTC)
Line 221 ⟶ 233:
 
The references in this section seem to be broken and/or 5+ years old; they also look to be primary. Anyone have better ones? If not, I suggest deletion. [[User:Chronodm|Chronodm]] ([[User talk:Chronodm|talk]]) 22:16, 27 October 2011 (UTC)
: I agree: unless we find a source that states that "we give problem solutions in Java more/less time since Java is slower/faster", we should not include any information about these contests. [[User:1exec1|1exec1]] ([[User talk:1exec1|talk]]) 20:01, 29 October 2011 (UTC)
:: For lazy people: 3rd ref:<p>
::''Concretely speaking, Java programs are allowed to run for THREE TIMES the time limit and are given another 150MS for each input file out of consideration for I/O efficiency. ''<p>
::4rd ref:<p>
::''7. Since Java program runs slow, The time limit of each problem will be about twice of the original, and the memory limit is enlarged to 1024M. Notice it may not enough for some problems.''
::Or sometimes they give time limits separate for each problem, like that: http://opencup.ru/files/oca/gp1/problems-e.pdf - where time limits for Java solutions of problems C,D,G,I are 1.75-3.5 times more...[[User:Alliumnsk|Alliumnsk]] ([[User talk:Alliumnsk|talk]]) 07:18, 13 November 2011 (UTC)
: I suggest you to read the references first. Dates: The first one, says ''This entry was posted by connect4 on Tuesday, June 8th, 2010 at 12:40 pm. '' at its bottom. In the second one, if you happen to get through first sentence, you can see date February, 2 2009, which indicates the source is newer that that, which doesn't fit into "5+ years" you mentioned. Now, would you delete links to Dr.Dobbs which are 6 years old? [[User:Alliumnsk|Alliumnsk]] ([[User talk:Alliumnsk|talk]]) 06:54, 13 November 2011 (UTC)
 
== Program speed Collections bullet point ==
 
I'm going to remove this bullet point from the Program speed section for now:
<blockquote>
Collections,[50][51] Heap allocation, as well as method calls[52] are much better in Java than in C++.
</blockquote>
because, looking at the cited article, I think the word "collections" there is a misleading characterisation, but I'm not sure the correct way to reword it. The most obvious thing is that the cited graphs aren't comparing collections performance in general, it's specifically looking at HashMaps. But I don't think changing it from "Collections" to "HashMaps" would be enough.
 
The code the author provides shows that that test consists of two loops which: allocate memory off the heap, convert an integer into a string, do a hash-table lookup or insert, and then deallocate the memory. There's no way the hash-table lookups make up more than a fraction of the time for that in either language. Also, in the C++ benchmark, the integer conversion is done using generic IO routines, while the Java benchmark uses an integer-to-string function. So the actual performance comparison is with heap allocation and C++ I/O routines vs. Java string conversions. That's a pretty complex and highly-specific thing to put in that bullet point in place of "Collections."
 
I figured I'd [[WP:BOLD|be bold]] in removing the misleading bit, but let the more involved editors make a judgement call on how to fix it. Personally, I think "Collections" should just be removed from the bullet point, because going from "heap allocation, I/O routines, string conversions, and hash maps" to "collections" seems like a bit of [[WP:OR|original research]] to me. (The [52] graph also looks far too close to justify saying "much better," especially since the C++ compilers fall between the server JVM and client JVM.)
 
More broadly, though, regarding using that article as a source here, it may be worth reconsidering whether the cited article actually says what's being attributed to it. The author deliberately chooses not to analyse or explain the results. If we use those graphs to assert that one language is faster than another in some case, we're choosing to interpret the results ourselves. [[User:BMKane|BMKane]] ([[User talk:BMKane|talk]]) 20:33, 25 November 2011 (UTC)
: I add this article as a source myself, and I'm against removing parts of it just because editors here (''editors'' include me as well) feel that the article is to broad or insufficiently explain the context of some performance comparison. The article does not write that java is faster than C++, it just present benchmarks about specific low level operations, and find some which are much faster in C++, some which are faster in Java. It's true that the benchmark about Collections was about various kinds of maps, however I don't understand why you want to remove the reference as well, rather than just change it to Maps. And removing a valid source (I don't think anyone would imply that Dr Dobbs source should be deemed not valid by default) seems really odd to me. Why not just stick to rewording what you thought should be reworded, rather than removing everything? The article talked about single Hashmapsand multiple Hashmaps, so even if I agree that naming it as Collection is too broad, maps is really the term that should be used here. [[User:Hervegirod|Hervegirod]] ([[User talk:Hervegirod|talk]]) 16:47, 26 November 2011 (UTC)
 
==Memory overhead source==
I removed the source for the java memory overhead here: ''This leads to a [http://www.codeproject.com/KB/dotnet/RuntimePerformance.aspx significant memory overhead] for small applications when compared to its best known competitors [[Mono (software)|Mono]] or [[.NET Framework|.Net]]'', and i added a fact tag. While it's generally accepted that Java has a significant memory overhead, the comparison with .NET and Mono in the source is not valid:
* the author is not known at all, and the article was not chosen or edited at all, it has the same validity than a blog by any individual
* furthermore, the programs he used to do the comparison for each language do not do the same thing at all, they are not equivalent. For example, for WPF / MFC / Forms, the author chose not to show any UI at all, he only started the UI framework. While for Java he also created a frame with various elements in it. [[User:Hervegirod|Hervegirod]] ([[User talk:Hervegirod|talk]]) 23:28, 5 January 2012 (UTC)
[[User:Hervegirod|Hervegirod]] ([[User talk:Hervegirod|talk]]) 23:23, 5 January 2012 (UTC)
 
== Compiler optimizations category ==
 
I removed this article from the [[:Category:Compiler optimizations|compiler optimizations]] category as it seems to me that that category is for, well, optimizations that a compiler can do, not things that use compiler optimizations. —[[User:Icktoofay|Icktoofay]] ([[User talk:Icktoofay|talk]]) 03:38, 15 January 2013 (UTC)
 
== removing POV tag with no active discussion per [[Template:POV]] ==
 
I've removed an old neutrality tag from this page that appears to have no active discussion per the instructions at [[Template:POV]]:
::This template is not meant to be a permanent resident on any article. Remove this template whenever:
::#There is consensus on the talkpage or the NPOV Noticeboard that the issue has been resolved
::#It is not clear what the neutrality issue is, and no satisfactory explanation has been given
::#In the absence of any discussion, or if the discussion has become dormant.
 
Since there's no evidence of ongoing discussion, I'm removing the tag for now. If discussion is continuing and I've failed to see it, however, please feel free to restore the template and continue to address the issues. Thanks to everybody working on this one! -- [[User:Khazar2|Khazar2]] ([[User talk:Khazar2|talk]]) 18:47, 29 June 2013 (UTC)
 
== Citations saying JNI is slow are very old ==
 
One of them is explicitly from 2001, and the other had no explicit date I could find but mentioned some of its tests as being performed under Windows 98.
 
These citations do not give me confidence that this is still the case, and I would recommend the section be updated, or at least that a <nowiki>{{Update|inaccurate=yes}}</nowiki> tag be added to the section.
 
== Program Speed, the quake comparison ==
 
 
It's downright silly to say that a JIT Compiled Java version of Quake is faster than a 16+ year old 32-bit, C version of Quake. (Remember Moore's Law?) If the source code is available to RECOMPILE a Java program, then it's ALSO available to recompile a C program with modern optimizations. I don't have a "side" in this debate. I only ask that the comparisons made be actual, factual, fair ones.
 
Cache size and speed has change. Optimizations have changed (loop unrolling can overload cache size). Numbers of CPU's/cores has changed. If we're going to compare C and Java, they should both be using--at the very least--compilers from the same era.
[[User:Novous|Novous]] ([[User talk:Novous|talk]]) 06:27, 7 December 2013 (UTC)
 
== Blacklisted Links Found on the Main Page ==
 
Cyberbot II has detected that page contains external links that have either been globally or locally blacklisted.
Links tend to be blacklisted because they have a history of being spammed, or are highly innappropriate for Wikipedia.
This, however, doesn't necessarily mean it's spam, or not a good link.
If the link is a good link, you may wish to request whitelisting by going to the [[MediaWiki talk:Spam-whitelist|request page for whitelisting]].
If you feel the link being caught by the blacklist is a false positive, or no longer needed on the blacklist, you may request the regex be removed or altered at the [[MediaWiki talk:Spam-blacklist|blacklist request page]].
If the link is blacklisted globally and you feel the above applies you may request to whitelist it using the before mentioned request page, or request it's removal, or alteration, at the [[meta:Talk:Spam Blacklist|request page on meta]].
When requesting whitelisting, be sure to supply the link to be whitelisted and wrap the link in nowiki tags.
The whitelisting process can take its time so once a request has been filled out, you may set the invisible parameter on the tag to true.
Please be aware that the bot will replace removed tags, and will remove misplaced tags regularly.
 
'''Below is a list of links that were found on the main page:'''
 
*<nowiki>http://java.dzone.com/articles/escape-analysis-java-6-update</nowiki>
*:''Triggered by <code>\bdzone\.com\b</code> on the global blacklist''
 
If you would like me to provide more information on the talk page, contact [[User:Cyberpower678]] and ask him to program me with more info.
 
From your friendly hard working bot.—[[User:Cyberbot II|<span style="color:green;font-family:Neuropol">cyberbot II</span>]] [[User talk:Cyberbot II|<sup style="color:green;font-family:arnprior">Notify</sup>]]<sub style="margin-left:-6.1ex;color:green;font-family:arnprior">Online</sub> 18:33, 8 December 2013 (UTC)
 
== Self-contradictory Information in Summary and Body ==
 
The opening summary states that Java performance is "not much different" from C++ citing a [http://blog.cfelde.com/2010/06/c-vs-java-performance/ blog article] which claims that "it's a tie." The body of the article states that Java micro-benchmark "performance is generally slower than or similar to compiled languages such as C or C++," referencing the [http://benchmarksgame.alioth.debian.org/u64q/java.php Computer Language Benchmarks Game]. The latter is a weaker and, in my opinion after reviewing both sources, probably the more accurate claim. I recommend making the claims in both sections consistent with one another. Thoughts? 21:31, 4 Mar 2013 (UTC) <span style="font-size: smaller;" class="autosigned">— Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[Special:Contributions/70.167.172.2|70.167.172.2]] ([[User talk:70.167.172.2|talk]]) </span><!-- Template:Unsigned IP --> <!--Autosigned by SineBot-->
 
== Reference 4 ==
 
Reference number 4 is a dead link that leads to a parked website. Can someone please fix this? [[Special:Contributions/134.129.205.205|134.129.205.205]] ([[User talk:134.129.205.205|talk]]) 22:43, 11 December 2014 (UTC)
 
== First sentence of "Comparison to other languages" ==
 
"Objectively comparing the performance of a Java program and an equivalent one written in another language such as C++ needs a carefully and thoughtfully constructed benchmark which compares programs expressing algorithms written in as identical a manner as technically possible."
 
Try this: "Objectively comparing the performance of a Java program and an equivalent one written in another language such as C++ needs a carefully and thoughtfully constructed benchmark which compares programs completing identical tasks." How one would design and code something in Java should have no impact on how you design and code it in C++ and vice versa. Imagine applying that rule in, say, a JavaScript vs. 6502 assembler comparison. - [[User:Richfife|Richfife]] ([[User talk:Richfife|talk]]) 20:43, 29 April 2016 (UTC)
 
== "Other compilers almost always target a specific hardware and software platform, producing machine code that will stay virtually unchanged during execution. " ==
 
This is basically saying Java has an advantage because it is compiled specifically for the hardware that it runs on. I see variations on the claim a lot, but to be honest, it's put up or shut up time. Is there any real world evidence that statically compiled code running on a modern processor can be significantly outperformed by code compiled per machine? I've not seen any. - [[User:Richfife|Richfife]] ([[User talk:Richfife|talk]]) 21:58, 29 April 2016 (UTC)
 
== "Speed" ? ==
 
While performance of running programs is covered, something everyone knows but never discussed is how slow java server apps (jvms) are to start (and stop). I don't think it's a small matter, either, as a simple restart is no longer trivial enough to not have to build tooling around, since restarts can take over a minute (and cause outages). I feel it should be mentioned. <!-- Template:Unsigned --><small class="autosigned">—&nbsp;Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[User:Kelt65|Kelt65]] ([[User talk:Kelt65#top|talk]] • [[Special:Contributions/Kelt65|contribs]]) 00:14, 20 October 2016 (UTC)</small> <!--Autosigned by SineBot-->
 
== External links modified ==
 
Hello fellow Wikipedians,
 
I have just modified 6 external links on [[Java performance]]. Please take a moment to review [[special:diff/811641512|my edit]]. If you have any questions, or need the bot to ignore the links, or the page altogether, please visit [[User:Cyberpower678/FaQs#InternetArchiveBot|this simple FaQ]] for additional information. I made the following changes:
*Added archive https://web.archive.org/web/20100331155325/http://www.cherrystonesoftware.com/doc/AlgorithmicPerformance.pdf to http://www.cherrystonesoftware.com/doc/AlgorithmicPerformance.pdf
*Added {{tlx|dead link}} tag to https://jdk.dev.java.net/verifier.html
*Added archive https://web.archive.org/web/20070105224757/http://weblogs.java.net/blog/campbell/archive/2005/07/strcrazier_perf.html to http://weblogs.java.net/blog/campbell/archive/2005/07/strcrazier_perf.html
*Added archive https://web.archive.org/web/20060516011057/http://forums.java.net/jive/thread.jspa?messageID=94530 to http://forums.java.net/jive/thread.jspa?messageID=94530
*Added archive https://web.archive.org/web/20080221131118/http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=195 to http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=195
*Added archive https://web.archive.org/web/20050214080519/http://janet-project.sourceforge.net/papers/jnibench.pdf to http://janet-project.sourceforge.net/papers/jnibench.pdf
*Added {{tlx|dead link}} tag to https://jna.dev.java.net/
*Added archive https://web.archive.org/web/20091015215436/http://developer.yahoo.net/blogs/hadoop/2008/07/apache_hadoop_wins_terabyte_sort_benchmark.html to http://developer.yahoo.net/blogs/hadoop/2008/07/apache_hadoop_wins_terabyte_sort_benchmark.html
 
When you have finished reviewing my changes, you may follow the instructions on the template below to fix any issues with the URLs.
 
{{sourcecheck|checked=false|needhelp=}}
 
Cheers.—[[User:InternetArchiveBot|'''<span style="color:darkgrey;font-family:monospace">InternetArchiveBot</span>''']] <span style="color:green;font-family:Rockwell">([[User talk:InternetArchiveBot|Report bug]])</span> 23:21, 22 November 2017 (UTC)
 
== Most of the memory use section is really odd nitpicks ==
 
For example, "if the size of an object is not 8, it is rounded up to 8" is not just something Java does -- it's C++ and other such languages too. Citing this as a Java thing is not exactly prudent. As well, the lack of address arithmetic (as said in article) is simply a consequence of a GC-based language, and most of the structures listed aren't something I see as necessitated.
 
The memory use of the JVM and such are per-implementation, and therefore not something that can be broadly said to apply to Java.[[Special:Contributions/216.186.142.254|216.186.142.254]] ([[User talk:216.186.142.254|talk]]) 19:34, 16 August 2019 (UTC)