Bug #10999
closed[PERF] bm_hash_aref_flo.rb
Description
Before: 0.066s
After 3bcf9fb53e4b9efabb15a3091fddfb68e5b6fbbe: 0.094
To view the full graph, please visit http://rubybench.org/ruby/ruby/commits?result_type=hash_aref_flo&display_count=200.
To issue is meant to highlight what we're seeing at RubyBench.org, feel free to close this issue if the trade offs were intended.
Updated by nobu (Nobuyoshi Nakada) about 9 years ago
It is not a realistic benchmark, that integer parts are all different.
Adding floats with same integer parts shows very bad result in the older version, whereas the latest version does not.
h = {}
strs = [*1..10000].map! {|i| i.fdiv(100)}
strs.each { |s| h[s] = s }
50.times { strs.each { |s| h[s] } }
benchmark results:
Execution time (sec)
name | old | new |
---|---|---|
hash_aref_flo | 0.942 | 0.084 |
Speedup ratio: compare with the result of `old' (greater is better)
name | new |
---|---|
hash_aref_flo | 11.175 |
This is because the older code ignored fraction parts, and it became neary linear search.
Updated by nobu (Nobuyoshi Nakada) about 9 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
Applied in changeset r50084.
bm_hash_aref_flo.rb: fix data
- benchmark/bm_hash_aref_flo.rb: make more realistic data.
[ruby-core:68632] [[Bug #10999]
Updated by nobu (Nobuyoshi Nakada) about 9 years ago
- Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN to 2.0.0: DONTNEED, 2.1: DONTNEED, 2.2: REQUIRED
Updated by tgxworld (Guo Xiang Tan) about 9 years ago
Thanks Nobu! I'll updated and backfill the new benchmark on our end as well. Thanks for looking into this!
Updated by ko1 (Koichi Sasada) about 9 years ago
Nobuyoshi Nakada wrote:
It is not a realistic benchmark, that integer parts are all different.
Why? I think it is possible case (I agree not so much case).
Maybe it is issue on Float#hash code.
Adding different (more possible) case is nice, but modifying benchmark and solving issue is not good way. Of course, if benchmark has a bug (not intended behavior), it should be solved.
Updated by nagachika (Tomoyuki Chikanaga) almost 9 years ago
- Backport changed from 2.0.0: DONTNEED, 2.1: DONTNEED, 2.2: REQUIRED to 2.0.0: DONTNEED, 2.1: DONTNEED, 2.2: DONE
Backported into ruby_2_2
branch at r50547.
I support ko1's comment. But I think the difference in benchmark scripts between branches are more misleading. So I backport the change.
I'm willing to backport the resurrection of the original benchmark. Please notice me by new ticket or change Backport
field.