Skip to content

Instantly share code, notes, and snippets.

@RX14
Forked from sdogruyol/string_benchmark.cr
Last active July 5, 2016 15:10
Show Gist options
  • Save RX14/20b64954e621897fa3d5f32bf9ba44fd to your computer and use it in GitHub Desktop.
Save RX14/20b64954e621897fa3d5f32bf9ba44fd to your computer and use it in GitHub Desktop.
require "benchmark"
STATUS_CODE = "200"
METHOD = "GET"
PATH = "api/v1/users"
IO = MemoryIO.new(100)
Benchmark.ips do |x|
x.report "Normal String" do
IO << "|#{STATUS_CODE}| #{METHOD} #{PATH}"
IO.rewind
end
x.report "Builder" do
IO << '|' << STATUS_CODE << "| " << METHOD << ' ' << PATH
IO.rewind
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment