Java performance: Difference between revisions

Content deleted Content added
Citation bot (talk | contribs)
Add: title. Changed bare reference to CS1/2. | Use this bot. Report bugs. | Suggested by BrownHairedGirl | #UCB_webform 803/1917
Citation bot (talk | contribs)
Alter: title. | Use this bot. Report bugs. | Suggested by AManWithNoPlan | #UCB_CommandLine
Line 369:
{{Disputed section|Most_of_the_memory_use_section_is_really_odd_nitpicks|date=August 2019}}
Java memory use is much higher than C++'s memory use because:
*There is an overhead of 8 bytes for each object and 12 bytes for each array<ref>{{Cite web|url=http://www.javamex.com/tutorials/memory/object_memory_usage.shtml|title = How to calculate the memory usage of Java objects}}</ref> in Java. If the size of an object is not a multiple of 8 bytes, it is rounded up to next multiple of 8. This means an object holding one byte field occupies 16 bytes and needs a 4-byte reference. C++ also allocates a [[Pointer (computer programming)|pointer]] (usually 4 or 8 bytes) for every object which class directly or indirectly declares [[virtual function]]s.<ref>{{cite web |url=http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=195 |title=ArchivedInformIT: copyC++ Reference Guide > the Object Model |access-date=June 22, 2009 |url-status=dead |archive-url=https://web.archive.org/web/20080221131118/http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=195 |archive-date=February 21, 2008 |df=dmy-all }}</ref>
*Lack of address arithmetic makes creating memory-efficient containers, such as tightly spaced structures and [[XOR linked list]]s, currently impossible ([[Project Valhalla (Java language)|the OpenJDK Valhalla project]] aims to mitigate these issues, though it does not aim to introduce pointer arithmetic; this cannot be done in a garbage collected environment).
*Contrary to malloc and new, the average performance overhead of garbage collection asymptotically nears zero (more accurately, one CPU cycle) as the heap size increases.<ref>https://www.youtube.com/watch?v=M91w0SBZ-wc : Understanding Java Garbage Collection - a talk by Gil Tene at JavaOne</ref>
Line 503:
 
===In programming contests===
Programs in Java start slower than those in other compiled languages.<ref>{{Cite web |url=http://topcoder.com/home/tco10/2010/06/08/algorithms-problem-writing/ |title=Archived copyTCO10 |access-date=June 21, 2010 |archive-url=https://web.archive.org/web/20101018212921/http://topcoder.com/home/tco10/2010/06/08/algorithms-problem-writing/ |archive-date=October 18, 2010 |url-status=dead |df=dmy-all }}</ref><ref>{{cite web | url=http://acm.timus.ru/help.aspx?topic=java&locale=en | title=How to write Java solutions @ Timus Online Judge }}</ref> Thus, some online judge systems, notably those hosted by Chinese universities, use longer time limits for Java programs<ref>{{cite web | url=http://acm.pku.edu.cn/JudgeOnline/faq.htm#q11 | title=FAQ }}</ref><ref>{{Cite web |url=http://acm.tju.edu.cn/toj/faq.html#qj |title=ArchivedFAQ copy&#124; TJU ACM-ICPC Online Judge |access-date=May 25, 2010 |archive-url=https://web.archive.org/web/20100629135921/http://acm.tju.edu.cn/toj/faq.html#qj |archive-date=June 29, 2010 |url-status=dead |df=mdy-all }}</ref><ref>{{cite web | url=http://www.codechef.com/wiki/faq#How_does_the_time_limit_work | title=FAQ &#124; CodeChef }}</ref><ref>{{Cite web |url=http://acm.xidian.edu.cn/land/faq |title=ArchivedHomePage copyof Xidian Univ. Online Judge |access-date=November 13, 2011 |archive-url=https://web.archive.org/web/20120219004452/http://acm.xidian.edu.cn/land/faq |archive-date=February 19, 2012 |url-status=dead |df=dmy-all }}</ref><ref>{{cite web | url=http://poj.org/faq.htm#q9 | title=FAQ }}</ref> to be fair to contestants using Java.
 
==See also==