Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #36861
| 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 | One code is aggressively optimised, while another not. Why? |
| Date | Wed, 12 Jul 2017 10:07:15 +0200 |
| Organization | Decebal Computing |
| Lines | 43 |
| Message-ID | <87lgnu5b9o.fsf@munus.decebal.nl> (permalink) |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 8bit |
| Injection-Info | mx02.eternal-september.org; posting-host="e8a517cbf8a434ef2a7722cda775d5e8"; logging-data="2776"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/CxVRm9rs8xX5tu2bg+ikoXq9A+CV1qcM=" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) |
| X-Homepage | http://www.decebal.nl/ |
| Cancel-Lock | sha1:8MnhmT4T3Iu5tXx1tz9vT84/IDc= sha1:6GvuhzWH2llcLaqxZ+383tXAK0M= |
| Xref | csiph.com comp.lang.java.programmer:36861 |
Show key headers only | View raw
I am looking into some performance metrics. I have the following code:
long sum = 0L;
for (long i = start; i < end; ++i) {
sum += i;
}
And this code:
long sum = 0L;
for (int i = start; i < end; ++i) {
sum += i;
}
Start and end are defined like:
private static int end = Integer.MAX_VALUE;
private static int start = Integer.MIN_VALUE;
The second code takes about 50% more time to execute. No surprise
there. But the first code is aggressively optimised when run several
times (the fifth run is about 2½ million times faster as the first
run), while the second code is not optimised:
09:41:10: Timing long int
09:41:10: took 2.08E+00 seconds.
09:41:13: took 1.29E-03 seconds.
09:41:13: took 1.25E-04 seconds.
09:41:13: took 1.36E-06 seconds.
09:41:13: took 7.97E-07 seconds.
09:41:13: Timing long long
09:41:13: took 3.09E+00 seconds.
09:41:16: took 3.11E+00 seconds.
09:41:19: took 4.03E+00 seconds.
09:41:23: took 3.94E+00 seconds.
09:41:27: took 3.87E+00 seconds.
Why the difference?
--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
Back to comp.lang.java.programmer | Previous | Next — 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