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

Speed up IBAN#prettify #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

fwolfst
Copy link

@fwolfst fwolfst commented Sep 20, 2024

Replacing our own implementation with library code, I found that our implementation was slightly faster (upto 10%, more if you don't strip):

require 'benchmark'

n = 500_000

Benchmark.bmbm do |x|
  x.report('gsub') { n.times do 'DE02120300000000202051'.gsub(/(.{4})/, '\1 ').strip end }
  x.report('scan') { n.times do 'DE02120300000000202051'.scan(/.{1,4}/).join(' ').strip end }
end
Rehearsal ----------------------------------------
gsub   0.099721   0.000681   0.100402 (  0.100422)
scan   0.093662   0.000809   0.094471 (  0.094668)
------------------------------- total: 0.194873sec

           user     system      total        real
gsub   0.099239   0.001079   0.100318 (  0.100424)

Replacing our own implementation with library code, I found that our implementation was slightly faster (upto 10%, more if you don't strip):

```
require 'benchmark'

n = 500_000

Benchmark.bmbm do |x|
  x.report('gsub') { n.times do 'DE02120300000000202051'.gsub(/(.{4})/, '\1 ').strip end }
  x.report('scan') { n.times do 'DE02120300000000202051'.scan(/.{1,4}/).join(' ').strip end }
end
```

```
Rehearsal ----------------------------------------
gsub   0.099721   0.000681   0.100402 (  0.100422)
scan   0.093662   0.000809   0.094471 (  0.094668)
------------------------------- total: 0.194873sec

           user     system      total        real
gsub   0.099239   0.001079   0.100318 (  0.100424)
```
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.

1 participant