Document performance overhead in README - #61
Merged
Conversation
Danger ReportNo issues found. |
Add benchmarks/basic.rb comparing basic Ruby::Enum operations (constant access, value, key, key?, keys, values) against their plain Ruby equivalents (constants, Hash), and a rake benchmark:basic task to run it. Add a new 'Performance' subsection under Benchmarks in README.md documenting, with real numbers, that constant access has no measurable overhead while hash-backed lookups carry roughly 3-5x overhead vs. a plain Hash, that this overhead does not grow with subclass depth (see rake benchmark:inheritance), and that Ruby::Enum::Case is the one notable outlier at 50-100x slower than a native case statement (see rake benchmark:case). Co-authored-by: Copilot <[email protected]>
dblock
force-pushed
the
document-performance
branch
from
August 15, 2026 02:00
67f6c30 to
bf5bfb1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a new Performance subsection under Benchmarks in README.md, documenting the actual overhead of
Ruby::Enum's basic operations vs. plain Ruby equivalents, backed by a new benchmark script.Benchmarks added
benchmarks/basic.rb(rake benchmark:basic) compares, over 1,000,000 iterations:Colors::REDvs. a plain Ruby constantColors.value(:RED)vs.Hash#[]Colors.key('red')vs.Hash#keyColors.key?(:RED)vs.Hash#key?Colors.keys/Colors.valuesvs.Hash#keys/Hash#valuesSample results (may vary by machine)
README
The new Performance section summarizes:
value,key,key?,value?,keys,values) carry roughly 3-5x overhead vs. a plainHash, due to method dispatch/object wrapping.rake benchmark:inheritance).Ruby::Enum::Caseis the one notable outlier, at 50-100x slower than a nativecasestatement (seerake benchmark:case), since it's the only feature involving lambda construction/evaluation at call time.Testing
bundle exec rake(rubocop + rspec): 69 examples, 0 failures, rubocop clean (25 files)rake benchmark:basicrun manually to generate the numbers above