Skip to content

@elandesign /string-benchmark.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Different ways to build a 100MB string
require 'benchmark'
require 'stringio'
Benchmark.measure do
string = ''
100_000_000.times do
string << '0'
end
end
# => 17.530000 0.040000 17.570000 ( 17.794845)
Benchmark.measure do
array = []
100_000_000.times do
array << '0'
end
array.join
end
# => 62.730000 1.410000 64.140000 ( 64.138629)
Benchmark.measure do
io = StringIO.new
100_000_000.times do
io.write '0'
end
io.rewind
io.read
end
# => 167.350000 2.020000 169.370000 (169.494641)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.