Skip to content
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

Math.DivRem for speed? #31

Closed
b9chris opened this issue Jul 22, 2014 · 0 comments
Closed

Math.DivRem for speed? #31

b9chris opened this issue Jul 22, 2014 · 0 comments

Comments

@b9chris
Copy link

b9chris commented Jul 22, 2014

This is purely an optimization question, not a bug.

A number of places like the ISO code use the pattern:

ix = val % 10;
val /= 10;

From what digging I could do, .Net doesn't optimize this nearly as well as one might hope. However, there's already a .Net built-in to do both operations at once, introduced in .Net 2.0:

http://msdn.microsoft.com/en-us/library/yda5c8dx.aspx

I've not tried it, but I'm curious if it would perform more optimally than the large number of % then / in ISO, int, etc code.

If not, as you likely know there are many optimizations for the combined operation out there, including several that are specific to narrow ranges of inputs, which ISO dates in particular exhibit:

http://embeddedgurus.com/stack-overflow/2011/02/efficient-c-tip-13-use-the-modulus-operator-with-caution/

Including some extremely specialized ones if you happen to be dividing by a power of two:

http://blog.teamleadnet.com/2012/07/faster-division-and-modulo-operation.html

Just some thoughts on possible remaining optimizations. Exciting library!

kevin-montrose added a commit that referenced this issue Jul 26, 2014
kevin-montrose added a commit that referenced this issue Jul 26, 2014
…nsistent improvement; commiting now for future reference, but this option is going away; supercedes existing CustomInt code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant