Last active
November 14, 2017 07:41
-
-
Save akshaymohite/645bc240888f32469f45c31fcc166740 to your computer and use it in GitHub Desktop.
comparison.rb
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
params = {a: 4, b: 5, b: 4, to: 'akshay'} | |
mandatory_keys = [:from, :to, :caller_id, :call_type] | |
keys = params.keys | |
Benchmark.ips do |benchmark| | |
benchmark.report('new') { mandatory_keys.any?{|key| keys.include?(key)} } | |
benchmark.report('old') { mandatory_keys.all?{|key| params.keys.include?(key)} } | |
benchmark.compare! | |
end |
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
Warming up -------------------------------------- | |
new 148.784k i/100ms | |
old 117.088k i/100ms | |
Calculating ------------------------------------- | |
new 2.727M (± 7.5%) i/s - 13.688M in 5.048651s | |
old 1.888M (± 4.9%) i/s - 9.484M in 5.037043s | |
Comparison: | |
new: 2727112.1 i/s | |
old: 1887710.7 i/s - 1.44x slower |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment