Created
May 4, 2015 21:41
-
-
Save brennovich/91146f1758be459000ae 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' | |
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