Skip to content

Instantly share code, notes, and snippets.

@tarellel
Created February 11, 2021 20:25
Show Gist options
  • Save tarellel/83526c47ebf5ad226085ead25c835fde to your computer and use it in GitHub Desktop.
Save tarellel/83526c47ebf5ad226085ead25c835fde to your computer and use it in GitHub Desktop.
Ruby Single VS Double Quotes
require 'benchmark/ips'
Benchmark.ips do |x|
x.report('Single quotes') { 'String of Characters' }
x.report('Double Quotes') { "String of Characters" }
x.compare!
end
# Warming up --------------------------------------
# Single quotes 1.745M i/100ms
# Double Quotes 1.736M i/100ms
# Calculating -------------------------------------
# Single quotes 17.583M (± 1.1%) i/s - 89.016M in 5.063070s
# Double Quotes 17.241M (± 2.9%) i/s - 86.818M in 5.040132s
#
# Comparison:
# Single quotes: 17583468.6 i/s
# Double Quotes: 17241297.9 i/s - same-ish: difference falls within error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment