mirror of
https://github.com/ruby/ruby.git
synced 2026-08-02 20:49:12 +08:00
#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.
14 lines
402 B
YAML
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!
|