Repository navigation
Commit 0601a80
Step 1: Add Symbol vs frozen String vs String keys in a 1000-key Hash (#135)
From #135 by @konung: whether String keys cost more than Symbol keys, and
whether freezing the String closes the gap. Symbol keys are the faster
ones, both to build a Hash with and to read it by.
Changes to the PR:
- Its 1000-pair file measured two things, so it is split into
hash/symbol-vs-string-keys-building.rb and
hash/symbol-vs-string-keys-reading.rb.
- Fixed keys and values instead of shuffle, rand and sample, so every
run measures the same work.
- Rank names: faster Symbol, fast frozen String, slow plain String. A
comment says why frozen keys are close when building: a Hash copies and
freezes a plain String key but keeps a frozen one as it is (checked on
Ruby 2.1 and 4.0).
- Not taken: the one-pair literal file ({symbol: 42} and friends). On
Ruby 3.4 and 4.0 each literal compiles to one duphash instruction, a
copy of a prebuilt Hash, so the reports measure the same work. It also
used Ruby 2.2 syntax ('sym_str': 42) and called the wrong method in one
report.
- Not taken either: code/hash/.tool-versions, and the CONTRIBUTING typo
fix, which main already has.
No README entry: the results move to the results site.
Co-authored-by: Nick Gorbikoff <72493+konung@users.noreply.github.com>1 parent 3ff4aba commit 0601a80
2 files changed
Lines changed: 61 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
0 commit comments