Commit c2b09d4
authored
**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 <fujita@clear-code.com>
1 parent 26812c8 commit c2b09d4
3 files changed
+6
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
150 | | - | |
| 150 | + | |
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
| |||
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
303 | | - | |
| 303 | + | |
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
| |||
313 | 313 | | |
314 | 314 | | |
315 | 315 | | |
316 | | - | |
| 316 | + | |
317 | 317 | | |
318 | 318 | | |
319 | 319 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
| 101 | + | |
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
| 105 | + | |
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
220 | 220 | | |
221 | 221 | | |
222 | 222 | | |
223 | | - | |
| 223 | + | |
224 | 224 | | |
225 | 225 | | |
226 | 226 | | |
| |||
0 commit comments