Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save keymastervn/b913a9df95b512cbd4bfdf541b3824a3 to your computer and use it in GitHub Desktop.
Save keymastervn/b913a9df95b512cbd4bfdf541b3824a3 to your computer and use it in GitHub Desktop.
benchmark_send__string_symbol_interpolation
require 'benchmark/ips'
def very_good_content
1+2+3+4+5
end
Benchmark.ips do |x|
x.report("string") { send :very_good_content }
x.report("symbol") { send 'very_good_content' }
x.report("string.to_sym") { send 'very_good_content'.to_sym }
x.report("string.interpolate") { send "very_good_#{'content'}" }
x.report("symbol.interpolate") { send :"very_good_#{'content'}" }
end
# ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-darwin19]
# Warming up --------------------------------------
# string 1.102M i/100ms
# symbol 600.117k i/100ms
# string.to_sym 573.269k i/100ms
# string.interpolate 586.101k i/100ms
# symbol.interpolate 994.886k i/100ms
# Calculating -------------------------------------
# string 11.068M (± 1.4%) i/s - 56.203M in 5.078929s
# symbol 5.800M (± 2.5%) i/s - 29.406M in 5.072989s
# string.to_sym 5.766M (± 1.6%) i/s - 29.237M in 5.071971s
# string.interpolate 5.841M (± 4.7%) i/s - 29.305M in 5.030705s
# symbol.interpolate 11.159M (± 1.6%) i/s - 56.709M in 5.082938s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment