Created
November 30, 2010 09:52
-
-
Save mloughran/721430 to your computer and use it in GitHub Desktop.
Appending to a string vs stringIO
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 'rubygems' | |
require 'benchmark' | |
require 'stringio' | |
Benchmark.bm do |x| | |
n = 1000000 | |
x.report('string') do | |
string = '' | |
appended = 'b' * 100 | |
n.times { string << appended } | |
end | |
x.report('stringio') do | |
string = StringIO.new | |
appended = 'b' * 100 | |
n.times { string << appended } | |
end | |
end | |
# user system total real | |
# string 0.360000 0.090000 0.450000 ( 0.441618) | |
# stringio 0.440000 0.100000 0.540000 ( 0.544054) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment