Created
August 23, 2015 23:32
-
-
Save chiting/72fbc06302dab308890f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "benchmark/ips" | |
C = "123456789012345678901" | |
A = "1234567890123456789012" | |
B = "12345678901234567890123" | |
D = "123456789012345678901234" | |
def slow | |
B + "x" | |
end | |
def fast | |
A + "x" | |
end | |
def slow_ref | |
D + "x" | |
end | |
def fast_ref | |
C + "x" | |
end | |
Benchmark.ips do |x| | |
x.report("#{C.length} chars") { fast_ref } | |
x.report("#{A.length} chars") { fast } | |
x.report("#{B.length} chars") { slow } | |
x.report("#{D.length} chars") { slow_ref } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With ruby 2.6.3 on mac OS 10.14.4 (which makes sense as the internals for String didn't change much since 1.9.3)