Alternative implemention of the Mod97-10 calculation#415
Conversation
|
IIRC, the refactor I did was limited by this class originally being public and used in several places where the input was not guaranteed, hence having to have length/buffer and character range safeguards. It only recently was deprecated and made internal. I'll have to check if the input can now be safely assumed base36 everywhere to your point 4). I don't remember if I tried 64-bit (u)long, and if I did, what the impact was but it does make sense, eliminates quite a few modulo ops. I will dive a bit deeper and integrate it in all various benchmarks (incl. older .NET) and check the outcome on my end and report back. Since there's several individual optimizations, I'd like to understand the effect/impact of each first ;) Thanks |
I assumed as much.
Yep. My first implementation (way back) used a big integer. Then, when I ported it to JavaScript/TypeScript, I moved a way form that (also for my .NET implementation), but (as written) reviewing my code again, I thought: what do I gain by reducing the number of modulo's. In this PR, I speeded up my implementation by 76%.
That is completely logical. Good luck with that! |
|
I revisited my implementation again, and made it even faster. Feel inspired: |
Recently, I stumbled on your IBAN project when I was searching for other IBAN validators/implementations. While setting up a benchmark between your and mine implementation, I also got an idea to improve the Mod97-10 implementation. (Later, I saw you tried something a bit similar).
Anyhow, My implementation is about twice as fast. So feel free to update the implementation.
So why is this faster?
If I use the following code to overcome point 4, the instead of 0.5, the ratio is between 0.65 and 0.60.
Qowaiv/Qowaiv#572