Skip to content

Instantly share code, notes, and snippets.

@tinogomes
Created September 30, 2015 13:36
Show Gist options
  • Save tinogomes/801d6ac730676b6b4391 to your computer and use it in GitHub Desktop.
Save tinogomes/801d6ac730676b6b4391 to your computer and use it in GitHub Desktop.
require 'benchmark/ips'
GC.disable
CYCLES = 1_000_000
SINGLE_QUOTES = 'string'
DOUBLE_QUOTES = "string"
Benchmark.ips do |x|
x.report('double quotes') { b = DOUBLE_QUOTES }
x.report('single quotes') { a = SINGLE_QUOTES }
x.compare!
end
@tinogomes
Copy link
Author

$ ruby string.rb
Calculating -------------------------------------
       double quotes    72.386k i/100ms
       single quotes    67.246k i/100ms
-------------------------------------------------
       double quotes      4.907M (±14.2%) i/s -     23.019M
       single quotes      4.784M (±13.8%) i/s -     23.065M

Comparison:
       double quotes:  4907015.4 i/s
       single quotes:  4783925.1 i/s - 1.03x slower

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment