Skip to content

Instantly share code, notes, and snippets.

@sdogruyol
Created July 5, 2016 14:58
Show Gist options
  • Save sdogruyol/f61a1000d215c9af67ab646fa41c8168 to your computer and use it in GitHub Desktop.
Save sdogruyol/f61a1000d215c9af67ab646fa41c8168 to your computer and use it in GitHub Desktop.
require "benchmark"
Benchmark.bm do |x|
$status_code = "200"
$method = "GET"
$path = "api/v1/users"
x.report "Normal String" do
10000000.times do
"|#{$status_code}| #{$method} #{$path}"
end
end
x.report "Builder" do
10000000.times do
builder = String::Builder.new
builder << "|"
builder << $status_code
builder << "|"
builder << " "
builder << $method
builder << " "
builder << $path
builder.to_s
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment