How to increase speed/performance of this function


This ec_mod_inv function is too slow and I would like to make it the fastest it can possibly be but I’m not sure if there is any room for improvement?

Does anyone know if this is the most performant implementation possible in Crystal?

In release mode it runs at:

           user       system     total     real
mod_inv:   0.003515   0.002847   0.006362  (0.003714)

Any help would be greatly appreciated


Someone still needs to implement this:

PRs are welcome!

The mutating API is a bit more verbose but you get the best performance out of it because you don’t need to allocate unnecessary GMP instances.

1 Like

Actually, it seems the discussion concluded in moving big numbers outside of the stdlib so I’m not sure. Also implementing all of these methods is a huge amount of work, and there are some subtle differences.

For starters, you can try using some of the code posted in the issue, apply it to your code and see what performance you get. If that speeds up thing, we can consider doing it (I could do it but it will take me some time).