Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
**Which issue(s) this PR fixes**: Fixes # **What this PR does / why we need it**: #match method returns MatchData, it has some cost to create the MatchData object. If it does not use MatchData object, it is better to use #match? method instead. * verify ```ruby require 'bundler/inline' gemfile do source 'https://rubygems.org' gem 'benchmark-ips' gem 'benchmark-memory' end Benchmark.ips do |x| pattern = /\{.*,.*\}/ path = 'path/to/file' x.report("match") { pattern.match(path) } x.report("match?") { pattern.match?(path) } x.compare! end ``` ``` ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux] Warming up -------------------------------------- match 1.082M i/100ms match? 1.683M i/100ms Calculating ------------------------------------- match 11.116M (± 0.8%) i/s (89.96 ns/i) - 56.266M in 5.062181s match? 16.779M (± 0.5%) i/s (59.60 ns/i) - 84.142M in 5.014786s Comparison: match?: 16779085.3 i/s match: 11115820.6 i/s - 1.51x slower ``` **Docs Changes**: **Release Note**: Signed-off-by: Shizuo Fujita <[email protected]>
- Loading branch information