Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #36259
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: execution speed when printing |
| Date | Tue, 14 Feb 2017 09:45:58 -0500 |
| Organization | A noiseless patient Spider |
| Lines | 43 |
| Message-ID | <o7v53q$7lr$1@dont-email.me> (permalink) |
| References | <speed-20170214014104@ram.dialup.fu-berlin.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 8bit |
| Injection-Date | Tue, 14 Feb 2017 14:44:10 -0000 (UTC) |
| Injection-Info | mx02.eternal-september.org; posting-host="616563f02882f59e8a2ff843b4737c27"; logging-data="7867"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Aq0SpFOIWDHXUgZRKreK3" |
| User-Agent | Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 |
| In-Reply-To | <speed-20170214014104@ram.dialup.fu-berlin.de> |
| Cancel-Lock | sha1:+E7gBP2VHz1B1wNq7r+54ZVC4N4= |
| Xref | csiph.com comp.lang.java.programmer:36259 |
Show key headers only | 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
Re: execution speed when printing Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-02-14 09:45 -0500
csiph-web