Sha256: e65cbc415e595fafd90ad9539a05a815fd7806d3e5fc45de90fe6900b460a69a
Contents?: true
Size: 595 Bytes
Versions: 58
Compression:
Stored size: 595 Bytes
Contents
require 'benchmark/ips' # 2 + 1 = 3 object def slow_plus 'foo' + 'bar' end # 2 + 1 = 3 object def slow_concat 'foo'.concat 'bar' end # 2 + 1 = 3 object def slow_append 'foo' << 'bar' end # 1 object def fast 'foo' 'bar' end def fast_interpolation "#{'foo'}#{'bar'}" end Benchmark.ips do |x| x.report('String#+') { slow_plus } x.report('String#concat') { slow_concat } x.report('String#append') { slow_append } x.report('"foo" "bar"') { fast } x.report('"#{\'foo\'}#{\'bar\'}"') { fast_interpolation } x.compare! end
Version data entries
58 entries across 29 versions & 2 rubygems