Skip to content

Instantly share code, notes, and snippets.

@rhysd
Created June 18, 2017 14:13
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 rhysd/0c7d256aaeeb48b9bc7181a333958143 to your computer and use it in GitHub Desktop.
Save rhysd/0c7d256aaeeb48b9bc7181a333958143 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'benchmark'
puts Benchmark.measure {
s = ""
5000000.times do
s << "hey, hey, "
end
}
puts Benchmark.measure {
s = StringIO.new
5000000.times do
s << "hey, hey, "
end
s.string
}
0.510000 0.020000 0.530000 ( 0.532377)
0.820000 0.030000 0.850000 ( 0.848875)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment