Sha256: 226b17c7b0d342c160e4796f71a78e85c850c69f9d708faa5171dbd8938201f8

Contents?: true

Size: 896 Bytes

Versions: 163

Compression:

Stored size: 896 Bytes

Contents

require 'rubygems'
require 'tach'

class Concatenator
  def initialize(string)
    @string = string
  end

  def call(data)
    @string << data
  end
end

string = "0123456789ABCDEF"

Tach.meter(100_000) do
  tach('class') do
    s = ""
    obj = Concatenator.new(s)
    10.times { obj.call(string) }
  end

  tach('lambda') do
    s = ""
    obj = lambda {|data| s << data }
    10.times { obj.call(string) }
  end
end

# ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-linux]
#
#  +--------+----------+
#  | tach   | total    |
#  +--------+----------+
#  | class  | 1.450284 |
#  +--------+----------+
#  | lambda | 2.506496 |
#  +--------+----------+

# ruby 1.8.7 (2010-12-23 patchlevel 330) [x86_64-linux]
#
#  +--------+----------+
#  | tach   | total    |
#  +--------+----------+
#  | class  | 1.373917 |
#  +--------+----------+
#  | lambda | 2.589384 |
#  +--------+----------+
  

Version data entries

163 entries across 161 versions & 6 rubygems

Version Path
excon-0.64.0 benchmarks/class_vs_lambda.rb
excon-0.63.0 benchmarks/class_vs_lambda.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/excon-0.62.0/benchmarks/class_vs_lambda.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/excon-0.62.0/benchmarks/class_vs_lambda.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/excon-0.62.0/benchmarks/class_vs_lambda.rb
excon-0.62.0 benchmarks/class_vs_lambda.rb
excon-0.61.0 benchmarks/class_vs_lambda.rb
excon-0.60.0 benchmarks/class_vs_lambda.rb
excon-0.59.0 benchmarks/class_vs_lambda.rb
excon-0.58.0 benchmarks/class_vs_lambda.rb
excon-0.57.1 benchmarks/class_vs_lambda.rb
excon-0.57.0 benchmarks/class_vs_lambda.rb
excon-0.56.0 benchmarks/class_vs_lambda.rb
excon-0.55.0 benchmarks/class_vs_lambda.rb
excon-0.54.0 benchmarks/class_vs_lambda.rb
excon-0.53.0 benchmarks/class_vs_lambda.rb
excon-0.52.0 benchmarks/class_vs_lambda.rb
excon-0.51.0 benchmarks/class_vs_lambda.rb
excon-0.50.1 benchmarks/class_vs_lambda.rb
excon-0.50.0 benchmarks/class_vs_lambda.rb