ruby/benchmark/string_capitalize.yml
Sampo Kuokkanen 217dd3d1fb
Improve performance of String#capitalize with a single-byte ASCII fast path
#upcase/#downcase already case-map ASCII strings with a plain byte
loop, but #capitalize/#capitalize! always went through full Unicode
case-mapping, making them ~10x slower on the same input. Add
capitalize_single (mirroring upcase_single/downcase_single), taken
whenever case_option_single_p() holds: it titlecases the first byte and
downcases the rest, touching ASCII letters only.
2026-06-20 16:14:45 +09:00

14 lines
402 B
YAML

prelude: |
str1 = [*"a".."m",*"N".."Z",*"0".."9"].join("")
str10 = str1 * 10
str100 = str10 * 10
str1000 = str100 * 10
benchmark:
capitalize-1: str1.capitalize
capitalize-10: str10.capitalize
capitalize-100: str100.capitalize
capitalize-1000: str1000.capitalize
capitalize!-1: str1.dup.capitalize!
capitalize!-100: str100.dup.capitalize!
capitalize!-1000: str1000.dup.capitalize!