Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #36901
| From | Cecil Westerhof <Cecil@decebal.nl> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: One code is aggressively optimised, while another not. Why? |
| Date | 2017-07-13 18:52 +0200 |
| Organization | Decebal Computing |
| Message-ID | <87a84846uu.fsf@munus.decebal.nl> (permalink) |
| References | <87lgnu5b9o.fsf@munus.decebal.nl> <ok58hq$s4n$1@dont-email.me> <87h8yg6ag8.fsf@munus.decebal.nl> <ok820t$786$1@dont-email.me> |
Eric Sosman <esosman@comcast-dot-net.invalid> writes:
> Remark: What's the point of all those Threads? The code
> never starts even one of them, never uses any of them for
> anything at all.
I use the Threads as parameter to the test function.
> Explanation/Rationale: Each test runs a loop to compute a sum,
> but the sum is never subsequently used for anything at all: It is
> not printed, it is not tested, it participates in no further
> computation of any kind. The JVM may well notice this and decide
> not to bother computing the sum since it isn't needed. A loop
> that starts out as
>
> long sum = 0;
> for (int i = start; i < end; ++i) {
> sum += i;
> }
>
> ... may then be transformed to
>
> for (int i = start; i < end; ++i) {
> }
>
> ... which (since the loop has no effect on anything except `i',
> which is itself not used outside the loop) may be further
> optimized to
>
> {
> }
>
> ... which casts just a wee bit of suspicion on the timings ;).
OK, I change the code to return the sum.
> I took the liberty of rewriting your test to eliminate the
> Threads, to print the calculated sums (restraining the JVM's
> eagerness to optimize), and to run a warm-up phase before the
> "in earnest" loops. I'd be happy to mail you the code if you'd
> like; maybe you can find as many "improvements" to mine as I did
> to yours.
I would appreciate it when you could email the code: I can only learn
from it.
--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
One code is aggressively optimised, while another not. Why? Cecil Westerhof <Cecil@decebal.nl> - 2017-07-12 10:07 +0200
Re: One code is aggressively optimised, while another not. Why? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-07-12 09:38 -0400
Re: One code is aggressively optimised, while another not. Why? Cecil Westerhof <Cecil@decebal.nl> - 2017-07-13 09:51 +0200
Re: One code is aggressively optimised, while another not. Why? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-07-13 11:05 -0400
Re: One code is aggressively optimised, while another not. Why? Cecil Westerhof <Cecil@decebal.nl> - 2017-07-13 18:52 +0200
Re: One code is aggressively optimised, while another not. Why? Cecil Westerhof <Cecil@decebal.nl> - 2017-07-13 19:51 +0200
Re: One code is aggressively optimised, while another not. Why? Joshua Cranmer đ§ <Pidgeot18@verizon.invalid> - 2017-07-12 09:19 -0500
Re: One code is aggressively optimised, while another not. Why? Martin Gregorie <martin@address-in-sig.invalid> - 2017-07-12 17:04 +0000
Re: One code is aggressively optimised, while another not. Why? Arne VajhĂžj <arne@vajhoej.dk> - 2017-07-12 21:02 -0400
csiph-web