Skip to content

Instantly share code, notes, and snippets.

@brennovich
Created May 4, 2015 21:41
Show Gist options
  • Save brennovich/91146f1758be459000ae to your computer and use it in GitHub Desktop.
Save brennovich/91146f1758be459000ae to your computer and use it in GitHub Desktop.
require 'benchmark/ips'
class Cocada
attr_accessor :string
def mocked_size
50
end
end
Benchmark.ips do |x|
x.time = 10
x.warmup = 2
x.report('accessing attribute reader') do
cocada = Cocada.new
cocada.string = ('Lorem Ipsum dolor sit amet' * rand(10))
cocada.mocked_size
end
x.report('live counting') do
cocada = Cocada.new
cocada.string = ('Lorem Ipsum dolor sit amet' * rand(10))
cocada.string.size
end
x.compare!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment