Skip to content

Instantly share code, notes, and snippets.

@k0kubun k0kubun/bench_dsd.rb Secret
Last active Sep 15, 2019

Embed
What would you like to do?
require 'benchmark_driver'
Benchmark.driver do |x|
x.prelude <<~EOS
# frozen_string_literal: true
@world = 'world'
EOS
x.report 'array', %q{
buf = []
buf << @world.to_s
buf << 'hello, '
buf << @world.to_s
buf.join
}
x.report 'hybrid', %q{
buf = []
buf << "#{@world}hello, #{@world}"
buf.join
}
end
Warming up --------------------------------------
array 3.387M i/s - 3.518M times in 1.038515s (295.23ns/i)
hybrid 3.702M i/s - 3.714M times in 1.003258s (270.12ns/i)
Calculating -------------------------------------
array 3.599M i/s - 10.161M times in 2.823170s (277.83ns/i)
hybrid 3.840M i/s - 11.106M times in 2.892639s (260.45ns/i)
Comparison:
hybrid: 3839502.9 i/s
array: 3599286.1 i/s - 1.07x slower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.