# ruby 2.6.0preview3 (2018-11-06 trunk 65578) [x86_64-darwin17]
#
#
# Warming up --------------------------------------
# Without Freeze 372.719k i/100ms
# With Freeze 451.989k i/100ms
# Calculating -------------------------------------
# Without Freeze 14.312M (± 2.3%) i/s - 71.562M in 5.002940s
# With Freeze 23.070M (± 3.5%) i/s - 115.257M in 5.003053s
#
# Comparison:
# With Freeze: 23070279.5 i/s
# Without Freeze: 14312418.6 i/s - 1.61x slower
#
require "benchmark/ips"
# Allocates new string over and over again
def without_freeze
"To freeze or not to freeze"
end
# Keeps and reuses shared string
def with_feeze
"To freeze or not to freeze".freeze
end
Benchmark.ips do |x|
x.report("Without Freeze") { without_freeze }
x.report("With Freeze") { with_feeze }
x.compare!
end
Created
December 17, 2018 11:29
-
-
Save 284km/e20efe3d3329486d3549ec7b96d1f769 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment