Created
January 6, 2018 22:29
-
-
Save chuckremes/94fdcb8b7dc5531124c506b210b0bd45 to your computer and use it in GitHub Desktop.
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
Charless-Air:ruby-io cremes$ ruby -v | |
rubinius 3.89.c15 (2.3.1 2ce10c98 2018-01-05 5.0.0) [x86_64-darwin16.7.0] | |
ACharless-Air:ruby-io cremes$ ruby benchmarks/keywords_vs_none.rb | |
Warming up -------------------------------------- | |
keywords 467.000 i/100ms | |
nokeywords 2.710k i/100ms | |
Calculating ------------------------------------- | |
keywords 4.970k (± 9.2%) i/s - 73.786k | |
nokeywords 30.586k (± 6.8%) i/s - 457.990k | |
Comparison: | |
nokeywords: 30586.3 i/s | |
keywords: 4969.6 i/s - 6.15x slower | |
Charless-Air:ruby-io cremes$ chruby 2.5.0 | |
Charless-Air:ruby-io cremes$ ruby benchmarks/keywords_vs_none.rb | |
Warming up -------------------------------------- | |
keywords 43.431k i/100ms | |
nokeywords 47.849k i/100ms | |
Calculating ------------------------------------- | |
keywords 555.418k (± 4.6%) i/s - 8.339M in 15.046999s | |
nokeywords 599.930k (± 5.8%) i/s - 8.996M in 15.049128s | |
Comparison: | |
nokeywords: 599930.0 i/s | |
keywords: 555418.3 i/s - same-ish: difference falls within error | |
Charless-Air:ruby-io cremes$ chruby jruby | |
Charless-Air:ruby-io cremes$ ruby benchmarks/keywords_vs_none.rb | |
Warming up -------------------------------------- | |
keywords 2.551k i/100ms | |
nokeywords 3.298k i/100ms | |
Calculating ------------------------------------- | |
keywords 32.387k (± 6.9%) i/s - 484.690k in 15.047407s | |
nokeywords 34.788k (± 5.4%) i/s - 521.084k in 15.026782s | |
Comparison: | |
nokeywords: 34788.3 i/s | |
keywords: 32386.8 i/s - same-ish: difference falls within error |
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 Ak | |
def initialize(to:) | |
@to = to | |
end | |
def read(a:, b:, c:, d: nil) | |
@to.read(a: a, b: b, c: c, d: d) | |
end | |
end | |
class Bk | |
def initialize(to:) | |
@to = to | |
end | |
def read(a:, b:, c:, d: nil) | |
@to.read(a, b, c, d) | |
end | |
end | |
class A | |
def initialize(to) | |
@to = to | |
end | |
def read(a, b, c, d=nil) | |
@to.read(a, b, c, d) | |
end | |
end | |
class E | |
def read(a, b, c, d) | |
Time.at(a.to_f + b.to_f + c.to_f + d.to_f) | |
end | |
end | |
with_words = Ak.new(to: Ak.new(to: Ak.new(to: Bk.new(to: E.new)))) | |
no_words = A.new(A.new(A.new(A.new(E.new)))) | |
Benchmark.ips do |x| | |
# Configure the number of seconds used during | |
# the warmup phase (default 2) and calculation phase (default 5) | |
x.config(:time => 15, :warmup => 5) | |
x.report("keywords") do |times| | |
i = 0 | |
while i < times | |
with_words.read(a: 3, b: 3**7.5, c: (3**7.5 % 3)) | |
i += 1 | |
end | |
end | |
x.report("nokeywords") do |times| | |
i = 0 | |
while i < times | |
no_words.read(3, 3**7.5, (3**7.5 % 3)) | |
i += 1 | |
end | |
end | |
# Compare the iterations per second of the various reports! | |
x.compare! | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment