Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #36257

Re: execution speed when printing

From Arne Vajhøj <arne@vajhoej.dk>
Newsgroups comp.lang.java.programmer
Subject Re: execution speed when printing
Date 2017-02-13 20:32 -0500
Organization Aioe.org NNTP Server
Message-ID <o7tmmt$mch$1@gioia.aioe.org> (permalink)
References <speed-20170214014104@ram.dialup.fu-berlin.de>

Show all headers | View raw


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


Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Re: execution speed when printing Arne Vajhøj <arne@vajhoej.dk> - 2017-02-13 20:32 -0500
  Re: execution speed when printing Eric Douglas <e.d.programmer@gmail.com> - 2017-02-14 07:47 -0800

csiph-web