Skip to content

Instantly share code, notes, and snippets.

@k0kubun

k0kubun/bench.rb Secret

Created June 23, 2017 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k0kubun/67a9b689e4f56b8e9d063594199bc066 to your computer and use it in GitHub Desktop.
Save k0kubun/67a9b689e4f56b8e9d063594199bc066 to your computer and use it in GitHub Desktop.
# 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
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