Created
February 27, 2023 10:52
-
-
Save jaynetics/c99d7f52bfafe2ff434a870721c067d4 to your computer and use it in GitHub Desktop.
Ruby benchmark for making empty, compare_by_identity Hash with new / literal vs dup
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
# results on ruby 3.2: | |
# | |
# Warming up -------------------------------------- | |
# new 277.194k i/100ms | |
# dup 394.839k i/100ms | |
# Calculating ------------------------------------- | |
# new 2.754M (± 1.9%) i/s - 13.860M in 5.034959s | |
# dup 4.006M (± 0.8%) i/s - 20.137M in 5.026561s | |
# | |
# Comparison: | |
# dup: 4006345.3 i/s | |
# new: 2753695.8 i/s - 1.45x (± 0.00) slower | |
require 'benchmark/ips' | |
H = {}.tap(&:compare_by_identity) | |
Benchmark.ips do |x| | |
x.report('new') { {}.tap(&:compare_by_identity) } | |
x.report('dup') { H.dup } | |
x.compare! | |
end; nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment