Created
June 21, 2017 23:18
-
-
Save flash-gordon/a30cc3af15655e1aa5be70601b9a7d7a to your computer and use it in GitHub Desktop.
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
require "benchmark/ips" | |
def foo(seq, kw) | |
end | |
def fast | |
kw = { a: 1, b: 2, c: 3 } | |
foo(1, kw) | |
end | |
def slow | |
kw = { a: 1, b: 2, c: 3 } | |
foo(1, **kw) | |
end | |
Benchmark.ips do |x| | |
x.report("fast code description") { fast } | |
x.report("slow code description") { slow } | |
x.compare! | |
end | |
__END__ | |
Warming up -------------------------------------- | |
fast code description | |
108.311k i/100ms | |
slow code description | |
50.038k i/100ms | |
Calculating ------------------------------------- | |
fast code description | |
1.596M (± 3.7%) i/s - 8.015M in 5.028700s | |
slow code description | |
576.682k (± 3.4%) i/s - 2.902M in 5.038684s | |
Comparison: | |
fast code description: 1596244.7 i/s | |
slow code description: 576682.4 i/s - 2.77x slower |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment