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.5.1 benchmarks/class_vs_lambda.rb
excon-0.5.0 benchmarks/class_vs_lambda.rb
excon-0.4.0 benchmarks/class_vs_lambda.rb