Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use #match? method instead of #match #4769

Merged
merged 1 commit into from
Jan 15, 2025
Merged

Conversation

Watson1978
Copy link
Contributor

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
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:

@Watson1978 Watson1978 requested a review from daipom January 14, 2025 06:33
Copy link
Contributor

@daipom daipom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!!

@daipom daipom merged commit c2b09d4 into fluent:master Jan 15, 2025
13 checks passed
@Watson1978 Watson1978 deleted the match branch January 15, 2025 04:29
@daipom daipom added this to the v1.19.0 milestone Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants