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


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

Re: execution speed when printing

Started byEric Sosman <esosman@comcast-dot-net.invalid>
First post2017-02-14 09:45 -0500
Last post2017-02-14 09:45 -0500
Articles 1 — 1 participant

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 Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-02-14 09:45 -0500

#36259 — Re: execution speed when printing

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2017-02-14 09:45 -0500
SubjectRe: execution speed when printing
Message-ID<o7v53q$7lr$1@dont-email.me>
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" );

     It might be faster.  It might be slower.  It might be faster
sometimes and slower at other times.

     Here's something that stands a chance of being not only more
user-friendly than either of the above, but perhaps faster, too:

	System.out.printf("%.1f miles%n", d);

(Argument: Whatever you expend in mucking about with a variadic
argument list, interpreting the format string, and assembling
the output may be far less than it would cost to print a dozen
or so utterly meaningless fraction digits.)

>   . 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.)

     If you don't have the time to write a microbenchmark studying
a question that interests you, is it reasonable to expect other
people to spend their time studying a matter of no interest to them?

>   If it is faster, should it be mentioned in a course for
>   beginners?

     No.  Whatever you may think of my other opinions, I beg you
to pay attention to this one: No.

-- 
esosman@comcast-dot-net.invalid
One thousand four hundred thirty-six days to go.

[toc] | [standalone]


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


csiph-web