Skip to content

Instantly share code, notes, and snippets.

@caleywoods
Created June 1, 2011 04:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caleywoods/1001800 to your computer and use it in GitHub Desktop.
Save caleywoods/1001800 to your computer and use it in GitHub Desktop.
irb(main):036:0> require 'benchmark'
=> true
irb(main):037:0> Benchmark.bmbm do |b|
irb(main):038:1* b.report("+=") do
irb(main):039:2* a = ""
irb(main):040:2> 100_000.times { a += "foo" }
irb(main):041:2> end
irb(main):042:1> b.report("<<") do
irb(main):043:2* a = ""
irb(main):044:2> 100_000.times { a << "foo" }
irb(main):045:2> end
irb(main):046:1> end
Rehearsal --------------------------------------
+= 15.507000 5.413000 20.920000 ( 21.429225)
<< 0.031000 0.000000 0.031000 ( 0.040003)
---------------------------- total: 20.951000sec
user system total real
+= 15.740000 5.273000 21.013000 ( 21.897252)
<< 0.031000 0.000000 0.031000 ( 0.036002)
=> [ 15.740000 5.273000 21.013000 ( 21.897252)
, 0.031000 0.000000 0.031000 ( 0.036002)
]
irb(main):047:0>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment