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

String#split seems to be faster than capturing digits with Regexp #50

Merged
merged 1 commit into from
Feb 23, 2024

Conversation

amatsuda
Copy link
Member

@amatsuda amatsuda commented Jan 6, 2023

Here's another tiny performance patch. The benchmark result below shows 1.23x speedup. Plus, the patched code should be more GC friendly.

addr = '192.168.1.99'
Benchmark.ips do |x|
  x.report('old') do
    m = RE_IPV4ADDRLIKE_OLD.match(addr) or return nil
    octets = m.captures
  end
  x.report('new') do
    RE_IPV4ADDRLIKE.match?(addr) or return nil
    octets = addr.split('.')
  end
  x.compare!
end

Warming up --------------------------------------
                 old   202.387k i/100ms
                 new   243.888k i/100ms
Calculating -------------------------------------
                 old      2.245M (± 2.1%) i/s -     11.334M in   5.049888s
                 new      2.764M (± 1.0%) i/s -     13.902M in   5.029862s

Comparison:
                 new:  2764111.4 i/s
                 old:  2245347.5 i/s - 1.23x  (± 0.00) slower

@amatsuda
Copy link
Member Author

amatsuda commented Jan 6, 2023

Ruby 2.3 tests are failing, because Regexp#match? was not implemented in that version yet. Should we still support that version here?

@hsbt
Copy link
Member

hsbt commented Jan 10, 2023

I'm +1 to drop to support Ruby 2.3 for performance improvement.

@tenderlove tenderlove merged commit afc3704 into ruby:master Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants