Skip to content

Instantly share code, notes, and snippets.


k0kubun/bench_sd.rb Secret

Created Sep 15, 2019
What would you like to do?
require 'benchmark_driver'
Benchmark.driver do |x|
x.prelude <<~EOS
# frozen_string_literal: true
@world = 'world'
EOS 'array', %q{
buf = []
buf << 'hello, '
buf << @world.to_s
} 'hybrid', %q{
buf = []
buf << "hello, #{@world}"
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)
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
You can’t perform that action at this time.