/gist:39d1ac550acf4e6380f1 Secret
Created
March 21, 2012 23:10
-
-
Save rubypanther/39d1ac550acf4e6380f1 to your computer and use it in GitHub Desktop.
benchmark
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
#!/usr/bin/env ruby | |
require 'benchmark' | |
include Benchmark | |
class AmountCalculated | |
attr_accessor :foos | |
def initialize *foos | |
self.foos = foos | |
end | |
def << rval | |
foos << [ rval ] | |
end | |
def + rval | |
self.class.new( foos + [ rval ] ) | |
end | |
end | |
am = AmountCalculated.new(%w! one two buckle my !) | |
bm do |b| | |
b.report('+') do | |
1_000_000.times do | |
am2 = AmountCalculated.new('shoe') | |
am += am2 | |
end | |
end | |
b.report('<<') do | |
1_000_000.times do | |
am2 = AmountCalculated.new('shoe') | |
am << am2 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment