Path: csiph.com!aioe.org!.POSTED!not-for-mail From: =?UTF-8?Q?Arne_Vajh=c3=b8j?= Newsgroups: comp.lang.java.programmer Subject: Re: execution speed when printing Date: Mon, 13 Feb 2017 20:32:16 -0500 Organization: Aioe.org NNTP Server Lines: 34 Message-ID: References: NNTP-Posting-Host: PBuS014lhzVyHjLbXmo/ZQ.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.java.programmer:36257 On 2/13/2017 7:48 PM, Stefan Ram wrote: > I believe that (assuming »d« has type »double«) > > java.lang.System.out.print( d ); > java.lang.System.out.println( " miles" ); > > might be faster than > > java.lang.System.out.println( d +" miles" ); > > . Do you think that on most implementations it will really > be faster? (Yes, I know. But would I write a post, if I had > time to write a microbenchmark? Moreover, a part of the cost > of the »+« might escape a microbenchmark, when it occurs in > a GC run that happens only much later but might increase the > overall runtime of a program.) > > Ok, printing to a console always is very slow, but the > output might be redirected to a file, and it might serve > as a model for similar situations that do not involve I/O. > > If it is faster, should it be mentioned in a course for > beginners? I think it would be a disaster to get beginners focused on that sort of premature optimization. Regarding the issue itself then it is not obvious to me that the concatenation is more expensive than the extra calls. Arne