Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rubypanther/39d1ac550acf4e6380f1 to your computer and use it in GitHub Desktop.
Save rubypanther/39d1ac550acf4e6380f1 to your computer and use it in GitHub Desktop.
benchmark
#!/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