-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐎 Make Timex.Duration.parse ~2x faster
It's very important for us at Duffel speedup the duration parsing. We're were investigating this function and we noticed a big number of calls to String.contains? that is a O(n) order algorithm in a loop. So we did a quick experiment on putting a flag on the number type while reading the chars. So it assumes that is a integer, until find a dot, where it changes the type to float. Then, it parses using Float or Integer depending on the flag. Avoiding the String.contains calls. The results were quite interesting: Before Timex.Duration.parse 500000 3322687 ~6.65µs/op Timex.Duration.parse 500000 1710993 ~3.42µs/op
- Loading branch information
1 parent
ed146ee
commit 767de3f
Showing
3 changed files
with
31 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters