-
-
Save k0kubun/67a9b689e4f56b8e9d063594199bc066 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
# frozen_string_literal: true | |
require 'benchmark/ips' | |
Benchmark.ips do |x| | |
x.report('+@') { +"" } | |
x.report('new') { String.new } | |
x.report('dup') { "".dup } | |
x.compare! | |
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 -------------------------------------- | |
+@ 439.631k i/100ms | |
new 387.940k i/100ms | |
dup 276.352k i/100ms | |
Calculating ------------------------------------- | |
+@ 11.340M (± 2.4%) i/s - 56.712M in 5.004134s | |
new 8.653M (± 1.7%) i/s - 43.449M in 5.022832s | |
dup 4.925M (± 4.6%) i/s - 24.595M in 5.007186s | |
Comparison: | |
+@: 11339997.4 i/s | |
new: 8652866.2 i/s - 1.31x slower | |
dup: 4924670.0 i/s - 2.30x slower |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment