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


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

Re: execution speed when printing

Started byArne Vajhøj <arne@vajhoej.dk>
First post2017-02-13 20:32 -0500
Last post2017-02-14 07:47 -0800
Articles 2 — 2 participants

Back to article view | Back to comp.lang.java.programmer

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  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

#36257 — Re: execution speed when printing

FromArne Vajhøj <arne@vajhoej.dk>
Date2017-02-13 20:32 -0500
SubjectRe: execution speed when printing
Message-ID<o7tmmt$mch$1@gioia.aioe.org>
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


[toc] | [next] | [standalone]


#36260

FromEric Douglas <e.d.programmer@gmail.com>
Date2017-02-14 07:47 -0800
Message-ID<2f66a1eb-a034-4a5a-8d4e-6315e3f3f1e7@googlegroups.com>
In reply to#36257
On Monday, February 13, 2017 at 8:32:23 PM UTC-5, Arne Vajhøj wrote:
> 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" );
> 
> 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

On a question so trivial, go with the Microsoft solution.  Software running slow?  Get better hardware.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web