Skip to content

Speedup String#{ indexOf, lastIndexOf } #2649

New issue

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

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

Already on GitHub? # to your account

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

MaxGraey
Copy link
Member

@MaxGraey MaxGraey commented Feb 13, 2023

This speedup indexOf matching, especially for long strings and single character.

Benchmark results:

Old
 - SAMPLE22_0:ok:  69.700 ms
 - SAMPLE22_0:eof: 49.000 ms
 - SAMPLE63_1:ok:  90.700 ms
 - SAMPLE63_1:eof: 87.200 ms
 - SAMPLE1k_h:ok:  345.100 ms
 - SAMPLE1k_h:eof: 723.800 ms

New
 - SAMPLE22_0:ok:  40.600 ms  (~1.7x)
 - SAMPLE22_0:eof: 39.400 ms  (~1.3x)
 - SAMPLE63_1:ok:  64.900 ms  (~1.4x)
 - SAMPLE63_1:eof: 54.900 ms  (~1.6x)
 - SAMPLE1k_h:ok:  318.900 ms (~1.0x)
 - SAMPLE1k_h:eof: 350.800 ms (~2.0x)

Benchmark Playground: https://tinyurl.com/pjftv9pp

  • I've read the contributing guidelines
  • I've added my name and email to the NOTICE file

@MaxGraey MaxGraey changed the title Speedup String#{ indexOf, lastIndexOf } is needle is single character Speedup String#{ indexOf, lastIndexOf } Feb 19, 2023
@MaxGraey MaxGraey marked this pull request as ready for review February 19, 2023 10:53
@MaxGraey MaxGraey marked this pull request as draft February 20, 2023 20:40
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant