Timeline for answer to How do I efficiently iterate over each entry in a Java Map? by Slava Vedenin
Current License: CC BY-SA 4.0
Post Revisions
21 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jul 18, 2022 at 16:03 | comment | added | GPI | @MiguelMunoz thanks. The idea was not to compare stream vs imperative, but capturing vs non capturing lambdas. just out of curiosity, btw, it's not that important to the question. | |
| Jul 11, 2022 at 23:33 | comment | added | ErikE | Thanks for the comment, but if it is so hard to understand Java's performance characteristics, then how is it not a piece of junk? Seriously, a for loop and a while loop shouldn't perform so much differently. | |
| Jul 9, 2022 at 1:01 | comment | added | MiguelMunoz | @ErikE Performance testing in Java is very hard, because we have no control over garbage-collecting, and I think because at some point the compiled classes may get optimized. In my trials, I run my tests for thousands of iterations, I interleave the different test cases, and I repeat my tests multiple times in each run. The first few runs are always slower. And when I plot speeds over time, I see time intervals where all my cases ran more slowly, probably due to garbage collection. And all cases see a performance improvement after a certain point, probably due to byte code optimization. | |
| Jul 9, 2022 at 0:40 | comment | added | MiguelMunoz | @GPI Two of the java8 apis are slower because they use Streams, which are inherently slower. They do all the work of a for-each loop—that's how they're implemented internally—but they also do some work setting up the stream. So they're never faster than a standard loop, unless you can correctly use parallel processing. Of course, we don't use them for speed but for readability and maintainability. (And we use object oriented languages instead of faster procedural ones because the developer time now costs more than the computer time. They optimize developer time instead of production time.) | |
| Aug 5, 2019 at 20:12 | history | edited | Lior Bar-On | CC BY-SA 4.0 |
minor typos
|
| Jan 2, 2019 at 13:00 | comment | added | KarelPeeters |
#8 is a terrible example, because of the parallel there's now a race condition when adding to i.
|
|
| Jul 14, 2018 at 19:04 | comment | added | ErikE |
#1 and #6 are exactly the same. Using while vs. a for loop is not a different technique for iterating. And I am surprised they have such variation between them in your tests—which suggests that the tests are not properly isolated from external factors unrelated to the things you intend to be testing.
|
|
| Apr 10, 2018 at 21:44 | history | edited | Java Devil | CC BY-SA 3.0 |
Single space error to fix the format of the second set of test results
|
| Mar 22, 2018 at 10:22 | history | edited | Peter Mortensen | CC BY-SA 3.0 |
Active reading. [<http://english.stackexchange.com/questions/4645> <http://en.wikipedia.org/wiki/GitHub>] Applied some formatting (as a result the diff looks much more extensive than it really is - use view "side-by-side markdown" to compare).
|
| Mar 22, 2018 at 10:17 | history | edited | Peter Mortensen | CC BY-SA 3.0 |
Active reading. [<http://english.stackexchange.com/questions/4645> <http://en.wikipedia.org/wiki/GitHub>] Applied some formatting (as a result the diff looks much more extensive than it really is - use view "side-by-side markdown" to compare).
|
| S Jan 17, 2018 at 18:53 | history | suggested | vancy-pants | CC BY-SA 3.0 |
Improved some of the wording for readability
|
| Jan 17, 2018 at 17:40 | review | Suggested edits | |||
| S Jan 17, 2018 at 18:53 | |||||
| Nov 7, 2017 at 23:37 | comment | added | Thierry | What about comparing the 3 main implementations : HashMap, LinkedHashMap and TreeMap ? | |
| Mar 17, 2017 at 18:28 | comment | added | Holger |
@ZhekaKozlov: look at the mindblowingly large error values. Consider that a test result of x±e implies that there were result within the interval from x-e to x+e, so the fastest result (1184.767±332.968) ranges from 852 to 1518, whereas the second slowest (1706.676±436.867) runs between 1270 and 2144, so the results still overlap significantly. Now look at the slowest result, 3289.866±1445.564, which implies diverging between 1844 and 4735 and you know that these test results are meaningless.
|
|
| Mar 16, 2017 at 18:21 | history | edited | ZhekaKozlov | CC BY-SA 3.0 |
edited body
|
| May 12, 2016 at 11:53 | comment | added | GPI |
@Viacheslav : very nice answer. Just wondering how Java8 apis are hindered, in your benchmark, by capturing lambdas... (e.g. long sum = 0; map.forEach( /* accumulate in variable sum*/); captures the sum long, which may be slower than say stream.mapToInt(/*whatever*/).sum for example. Of course you can not always avoid capturing state, but that may be a reasonnable addition to the bench.
|
|
| Apr 18, 2016 at 14:05 | history | edited | Slava Vedenin | CC BY-SA 3.0 |
added 17 characters in body
|
| Feb 26, 2016 at 8:22 | history | edited | Valentin Lorentz | CC BY-SA 3.0 |
Make image link use HTTPS
|
| Feb 22, 2016 at 16:51 | history | edited | Slava Vedenin | CC BY-SA 3.0 |
added 72 characters in body
|
| Feb 22, 2016 at 16:43 | history | edited | Slava Vedenin | CC BY-SA 3.0 |
added 21 characters in body
|
| Feb 22, 2016 at 16:37 | history | answered | Slava Vedenin | CC BY-SA 3.0 |