Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

容器篇中对于HashMap遍历方式的说明存在部分错误 #1411

Closed
houtaroy opened this issue Sep 23, 2021 · 1 comment
Closed

容器篇中对于HashMap遍历方式的说明存在部分错误 #1411

houtaroy opened this issue Sep 23, 2021 · 1 comment
Labels
typo Correct typos

Comments

@houtaroy
Copy link

1.5.8. HashMap 有哪几种常见的遍历方式?

此处引用公众号文章中, 对于parallelStream遍历方式的性能分析有误

先说结论, 存在阻塞时parallelStream性能最高, 非阻塞时parallelStream性能最低

当遍历不存在阻塞时, parallelStream的性能是最低的:

Benchmark               Mode  Cnt     Score      Error  Units
Test.entrySet           avgt    5   288.651 ±   10.536  ns/op
Test.keySet             avgt    5   584.594 ±   21.431  ns/op
Test.lambda             avgt    5   221.791 ±   10.198  ns/op
Test.parallelStream     avgt    5  6919.163 ± 1116.139  ns/op

加入阻塞代码Thread.sleep(10)后, parallelStream的性能才是最高的:

Benchmark               Mode  Cnt           Score          Error  Units
Test.entrySet           avgt    5  1554828440.000 ± 23657748.653  ns/op
Test.keySet             avgt    5  1550612500.000 ±  6474562.858  ns/op
Test.lambda             avgt    5  1551065180.000 ± 19164407.426  ns/op
Test.parallelStream     avgt    5   186345456.667 ±  3210435.590  ns/op
@Snailclimb Snailclimb added the typo Correct typos label Sep 25, 2021
@Ahaola
Copy link

Ahaola commented Apr 30, 2023

good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typo Correct typos
Projects
None yet
Development

No branches or pull requests

3 participants