[ruby-core:63477] [ruby-trunk - Bug #10003] [Open] Hash#fetch performance issue

From: richard.schneeman@...
Date: 2014-07-01 22:08:51 UTC
List: ruby-core #63477
Issue #10003 has been reported by Richard Schneeman.

----------------------------------------
Bug #10003: Hash#fetch performance issue
https://bugs.ruby-lang.org/issues/10003

* Author: Richard Schneeman
* Status: Open
* Priority: Normal
* Assignee:=20
* Category: core
* Target version:=20
* ruby -v: 2.1.2
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
It looks like there is a performance issue with Hash#fetch compared to Hash=
#[]. I found this issue via this gist: https://gist.github.com/jonleighton/=
3552829. I could not find it reported anywhere on the tracker, forgive me i=
f this is a known issue:

```
require 'benchmark/ips'
=20
h =3D { foo: :bar }
=20
Benchmark.ips do |r|
  r.report('#[]')    { h[:foo] }
  r.report('#fetch') { h.fetch(:foo) }
end

Calculating -------------------------------------
                 #[]    124893 i/100ms
              #fetch    121729 i/100ms
-------------------------------------------------
                 #[]  6917857.4 (=C2=B120.4%) i/s -   32472180 in   5.00883=
2s
              #fetch  4570251.5 (=C2=B118.8%) i/s -   22032949 in   5.01571=
2s
```

This is in Ruby 2.1.2



--=20
https://bugs.ruby-lang.org/

In This Thread

Prev Next