fastruby / fastruby/fast-ruby

`dup`ing an Identity Hash/Set is faster than creating a new one

オープン
#230 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Ruby
スター
5.7k
フォーク
371
PR マージ指標
30日以内にマージされた PR はありません

説明

It's one less allocation, too :)

| | YJIT off | YJIT on |
|------------------------------:|-----------:|-----------:|
| `Set.new.compare_by_identity` | 2.571M | 4.260M |
| `S.dup` | **3.014M** | **4.999M** |
| ∆ | **1.17x** | **1.17x** |

| | YJIT off | YJIT on |
|-------------------------------:|-----------:|-----------:|
| `Hash.new.compare_by_identity` | 5.643M | 8.208M |
| `H.dup` | **5.988M** | **9.014M** |
| ∆ | **1.06x** | **1.09x** |

```rb
S = Set.new.compare_by_identity.freeze
H = Hash.new.compare_by_identity.freeze

Benchmark.ips do |x|
x.config(time: 10)

x.report(".new.compare_by_identity") do |times|
i = 0
while (i += 1) <= times
S.dup
end
end

x.report(".dup ") do |times|
i = 0
while (i += 1) <= times
Set.new.compare_by_identity
end
end

x.compare!
end

Benchmark.ips do |x|
x.config(time: 10)

x.report(".new.compare_by_identity") do |times|
i = 0
while (i += 1) <= times
H.dup
end
end

x.report(".dup ") do |times|
i = 0
while (i += 1) <= times
Hash.new.compare_by_identity
end
end

x.compare!
end
```

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。