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


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

Re: One code is aggressively optimised, while another not. Why?

Path csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From Cecil Westerhof <Cecil@decebal.nl>
Newsgroups comp.lang.java.programmer
Subject Re: One code is aggressively optimised, while another not. Why?
Date Thu, 13 Jul 2017 18:52:25 +0200
Organization Decebal Computing
Lines 52
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>
Mime-Version 1.0
Content-Type text/plain
Injection-Info mx02.eternal-september.org; posting-host="cea988b749795bfe5e66959d383985c6"; logging-data="31281"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18BcHLUHe4crCjLl7L/FPHojj0m/5+2Bwk="
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)
X-Homepage http://www.decebal.nl/
Cancel-Lock sha1:NcTj/Rs+CIGJ/kZkTcKwE3no11k= sha1:6/x+ox1+T4/vM9lf+siJnd1Ws8Y=
Xref csiph.com comp.lang.java.programmer:36901

Show key headers only | View raw


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


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