Timeline for Project Euler #2 (Fibonacci Sequence)
Current License: CC BY-SA 3.0
17 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jan 10, 2015 at 22:55 | comment | added | Christian Hujer | @jrolfl You convinced me, and I have updated the answer accordingly. Thank you very much for insisting in getting this correct and proving me wrong in these two points. | |
Jan 10, 2015 at 22:54 | history | edited | Christian Hujer | CC BY-SA 3.0 |
@jrolfl convinced me in chat about the 2 points he was making. I updated the answer accordingly.
|
Jan 10, 2015 at 22:05 | comment | added | rolfl | @ChristianHujer - let's take this conversation to the 2nd monitor chat room | |
Jan 10, 2015 at 21:29 | comment | added | Christian Hujer | @rolfl here's the source which I used for profiling: pastebin.com/0uk1mFZG | |
Jan 10, 2015 at 21:25 | comment | added | Christian Hujer | @rolfl You should actually explain with evidence how that loop unrolling is bad - other than maintainability, that's what I already mentioned anyway. And as mentioned in the text, it's two, not just one comparison which this unrolled loop saves. | |
Jan 10, 2015 at 21:23 | comment | added | Christian Hujer |
@rolfl Method calls cost. Create a public static void empty() {} , call it from within the while() loop and measure. On my machine (AMD A8-3850), the difference is ~900ns which is almost 50%. Without call: 1022ns. With call: 1954ns. Taken the fastest in 100 runs: sum=0; for ((i=0; i<100; i++)) ; do java FiboSmart ; done | grep 'Time used:' | sed 's/Time used: //' | sort -n | head -n 1 I have quite strong evidence that method calls cost, and I would like to be disproved properly. Show me how I'm wrong. java version 1.8.0_25 build 1.8.0_25-b17 / build 25.25-b02, mixed mode
|
|
Jan 10, 2015 at 19:37 | comment | added | rolfl | There's a lot of (very) useful information in this answer, but the conclusions you have drawn are both faulty: 1. method calls are slower than no method calls, and this is why, normally, the code is compiled by the JIT compiler, and often methods are 'inlined' and there's no method call. Calling a method is not a performance problem you should worry about. 2. While this answer does unroll the loop, the performance gain here is because the sequence has the 3rd-value-always-even property, and there's no need to check. Unrolling loops for performance is bad (JIT does that too). | |
Jan 10, 2015 at 12:21 | history | edited | Christian Hujer | CC BY-SA 3.0 |
minor fixes
|
Jan 10, 2015 at 1:03 | comment | added | Legato | Gratitude for gracing such humble a question with such brilliant an answer. I especially appreciate this bit: "If you want to be fast, avoid method calls." I won't soon forget it. The loop unrolling is actually something I'd normally avoid for readability/compact code, but it's interesting to see that it actually increases performance, which I wouldn't have expected. A lot of the "under the hood" bits are above me but are nonetheless very well received. Thank you once more. | |
Jan 10, 2015 at 1:02 | history | edited | Christian Hujer | CC BY-SA 3.0 |
Fix glitches in assembly code
|
Jan 10, 2015 at 0:48 | vote | accept | Legato | ||
Jan 9, 2015 at 23:03 | history | edited | Christian Hujer | CC BY-SA 3.0 |
deleted 7 characters in body
|
Jan 9, 2015 at 22:57 | history | edited | Christian Hujer | CC BY-SA 3.0 |
Compare Add solution with Multiply solution.
|
Jan 9, 2015 at 22:50 | history | edited | Christian Hujer | CC BY-SA 3.0 |
Compare Add solution with Multiply solution.
|
Jan 9, 2015 at 22:22 | history | edited | Christian Hujer | CC BY-SA 3.0 |
added 297 characters in body
|
Jan 9, 2015 at 21:04 | history | edited | Christian Hujer | CC BY-SA 3.0 |
added 297 characters in body
|
Jan 9, 2015 at 20:54 | history | answered | Christian Hujer | CC BY-SA 3.0 |