Skip to content

Instantly share code, notes, and snippets.

@k0kubun

k0kubun/bench.rb Secret

Created June 23, 2017 16:15
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/e3da77cae2c132badd386c96f2de5768 to your computer and use it in GitHub Desktop.
Save k0kubun/e3da77cae2c132badd386c96f2de5768 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
require 'benchmark/ips'
Benchmark.ips do |x|
x.report('+@') { +"" }
x.report('dup') { "".dup }
x.compare!
end
Warming up --------------------------------------
+@ 436.074k i/100ms
dup 292.061k i/100ms
Calculating -------------------------------------
+@ 11.490M (± 1.9%) i/s - 57.562M in 5.011607s
dup 5.121M (± 1.7%) i/s - 25.701M in 5.020415s
Comparison:
+@: 11490470.9 i/s
dup: 5121009.0 i/s - 2.24x slower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment