Share

matchPattern is faster than findString

When searching for a substring inside a string, using the matchPattern() method is faster than using findString().

Executing the same method one million times on the same PC resulted in:

  • 3.7 seconds execution time for matchPattern

  • 5.9 seconds execution time for findString

  • 5.0 seconds execution time for subString when comparing the first 3 characters.

Previous Tip

Recursive functions can be faster

Next Tip

Do not use return, break, exit or continue

Was this information helpful?