This file contains 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
# Benchmark when objects are equivelant: | |
# frozen_string_literal: true | |
require 'benchmark/ips' | |
Benchmark.ips do |x| | |
a1 = (1..10_000).to_a | |
a2 = (1..10_000).to_a |
This file contains 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
o = Object.new | |
def o.say_hello | |
puts "Hello!" | |
end | |
o.say_hello | |
o.clone.say_hello |
This file contains 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
Calculating ------------------------------------- | |
old 307.000 i/100ms | |
new 13.803k i/100ms | |
------------------------------------------------- | |
old 3.136k (± 3.7%) i/s - 15.657k | |
new 155.048k (± 4.0%) i/s - 786.771k | |
Comparison: | |
new: 155047.6 i/s | |
old: 3135.6 i/s - 49.45x slower |
This file contains 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
Calculating ------------------------------------- | |
old 124.917k i/100ms | |
new 127.378k i/100ms | |
------------------------------------------------- | |
old 3.766M (± 5.0%) i/s - 18.862M | |
new 3.797M (± 4.8%) i/s - 18.979M | |
Comparison: | |
new: 3797241.3 i/s | |
old: 3765728.9 i/s - 1.01x slower |
This file contains 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
Calculating ------------------------------------- | |
== 11.195k i/100ms | |
eql? 14.323k i/100ms | |
------------------------------------------------- | |
== 119.132k (± 4.5%) i/s - 604.530k | |
eql? 158.007k (± 3.0%) i/s - 802.088k | |
Comparison: | |
eql?: 158006.6 i/s | |
==: 119131.6 i/s - 1.33x slower |
This file contains 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
Calculating ------------------------------------- | |
old 127.212k i/100ms | |
new 126.136k i/100ms | |
------------------------------------------------- | |
old 3.772M (± 8.8%) i/s - 18.573M | |
new 3.951M (± 5.8%) i/s - 19.803M | |
Comparison: | |
new: 3951356.5 i/s | |
old: 3771768.5 i/s - 1.05x slower |
This file contains 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
Calculating ------------------------------------- | |
old 317.000 i/100ms | |
new 14.732k i/100ms | |
------------------------------------------------- | |
old 3.189k (± 3.4%) i/s - 16.167k | |
new 158.659k (± 3.1%) i/s - 795.528k | |
Comparison: | |
new: 158658.9 i/s | |
old: 3189.4 i/s - 49.75x slower |
This file contains 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
require 'benchmark/ips' | |
class Hash | |
def old_compact | |
self.select { |_, value| !value.nil? } | |
end | |
def old_compact! | |
self.reject! { |_, value| value.nil? } |