mirror of
https://github.com/ruby/ruby.git
synced 2026-01-26 12:14:51 +00:00
Similar optimizations to the ones performed in GH-15907. - Skip the expensive multi-byte encoding handling for the common encodings that are known to be safe. - Use `CheckPath` to save on copying the argument and only scan it for NULL bytes once. - Create the return string with rb_enc_str_new instead of rb_str_subseq as it's going to be a very small string anyway. This could be optimized a little bit further by searching for both `.` and `dirsep` in one pass, ``` compare-ruby: ruby 4.1.0dev (2026-01-19T03:51:30Z master 631bf19b37) +PRISM [arm64-darwin25] built-ruby: ruby 4.1.0dev (2026-01-20T07:33:42Z master 6fb50434e3) +PRISM [arm64-darwin25] ``` | |compare-ruby|built-ruby| |:----------|-----------:|---------:| |long | 3.606M| 22.229M| | | -| 6.17x| |long_name | 2.254M| 13.416M| | | -| 5.95x| |short | 16.488M| 29.969M| | | -| 1.82x|
7 lines
271 B
YAML
7 lines
271 B
YAML
prelude: |
|
|
# frozen_string_literal: true
|
|
benchmark:
|
|
long: File.extname("/Users/george/src/github.com/ruby/ruby/benchmark/file_dirname.yml")
|
|
long_name: File.extname("Users_george_src_github.com_ruby_ruby_benchmark_file_dirname.yml")
|
|
short: File.extname("foo/bar")
|