-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
isISIN optimization #1633
isISIN optimization #1633
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1633 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 100 100
Lines 1807 1852 +45
=========================================
+ Hits 1807 1852 +45
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @bmacnaughton and sorry for the delay. A little question, isn't isISIN
using the luhn algorithm?
@tux-tn yes, it is. and it still is using the algorithm (it has to in order to work correctly). it's just executing it in one pass over the string now. but the performance benefits come mostly from not creating many substrings and running parseInt on each of them. it just makes one pass over the characters and converts them to the integer they represent directly. i didn't really have any need for this, but whenever i see that kind of pattern in code i look at it as a puzzle to be solved. here's an example, completely unrelated to this, that shows another case where the performance of a slightly larger solution is dramatically better: https://stackoverflow.com/questions/34309988/byte-array-to-hex-string-conversion-in-javascript/55426656#55426656 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tux-tn yes, it is. and it still is using the algorithm (it has to in order to work correctly). it's just executing it in one pass over the string now. but the performance benefits come mostly from not creating many substrings and running parseInt on each of them. it just makes one pass over the characters and converts them to the integer they represent directly.
i didn't really have any need for this, but whenever i see that kind of pattern in code i look at it as a puzzle to be solved. here's an example, completely unrelated to this, that shows another case where the performance of a slightly larger solution is dramatically better: https://stackoverflow.com/questions/34309988/byte-array-to-hex-string-conversion-in-javascript/55426656#55426656
Actually i was asking this to know if your optimization is related to luhn algorithm (other validators such as isCreditCard would profit from it) but after checking and running your code i understand that the optimization is related to string manipulation and type casting.
Thank you for taking the time to optimize the code and to do some benchmarking 👍
i was playing around and challenged myself to optimize
isISIN
. i'm not sure it's 100% there, but it's significantly more performant that it was.