-
-
Save k0kubun/4329c599685f467b212b565bb561743b to your computer and use it in GitHub Desktop.
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 << 'hello, ' | |
buf << @world.to_s | |
buf.join | |
} | |
x.report 'hybrid', %q{ | |
buf = [] | |
buf << "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 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