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


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

Re: execution speed when printing

From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: execution speed when printing
Date 2017-02-14 09:45 -0500
Organization A noiseless patient Spider
Message-ID <o7v53q$7lr$1@dont-email.me> (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" );

     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.

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


Thread

Re: execution speed when printing Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-02-14 09:45 -0500

csiph-web