This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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