Skip to content

Instantly share code, notes, and snippets.

@k0kubun
Created September 15, 2019 16:50
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 k0kubun/4329c599685f467b212b565bb561743b to your computer and use it in GitHub Desktop.
Save k0kubun/4329c599685f467b212b565bb561743b to your computer and use it in GitHub Desktop.
require 'benchmark_driver'
Benchmark.driver do |x|
x.prelude <<~EOS
# frozen_string_literal: true
@world = 'world'
EOS
x.report 'array', %q{
buf = []
buf << 'hello, '
buf << @world.to_s
buf.join
}
x.report 'hybrid', %q{
buf = []
buf << "hello, #{@world}"
buf.join
}
end
Warming up --------------------------------------
array 4.435M i/s - 4.661M times in 1.051023s (225.49ns/i, 902clocks/i)
hybrid 4.089M i/s - 4.092M times in 1.000707s (244.58ns/i)
Calculating -------------------------------------
array 4.673M i/s - 13.305M times in 2.847078s (213.99ns/i, 926clocks/i)
hybrid 4.307M i/s - 12.266M times in 2.848049s (232.19ns/i, 974clocks/i)
Comparison:
array: 4673041.7 i/s
hybrid: 4306811.8 i/s - 1.09x slower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment