The One Man MMO Project: Looking for a Fast Square RootLast night I needed a square root function that would work on 64bit unsigned integers. I have been using the standard library's sqrt, but my first thought was that an integer square root could be faster.
It turns out that the hardwarebased floating point sqrt is 9.45x faster than the "fast" integer square root. If I add a call to static_cast to get the float value into a uint64, it is still 8.27x faster. I'll keep the integer square root, but this post is going in the comments for it. Copyright (C)20092014 onemanmmo.com. All Rights Reserved

Homepage: www.onemanmmo.com email:one at onemanmmo dot com
Int Elapsed 571950us
Float Elapsed 38746us
Float + Cast Elapsed 56759us
Float is 14.76x faster, 10.08x with the static_cast.
Also, this was not the timing for one sqrt, but 4,000,000.
Homepage: omeg.pl email:
Sqrt float: 12583.508ms
Sqrt double: 12371.292ms
Fast uint sqrt: 24388.667ms
Fast ulong sqrt: 96830.309ms
That's for 1e9 loops with adding all sqrts together to prevent optimizer from ignoring the values. Also did the same test in C# for fun:
Sqrt double: 13547ms
Fast uint sqrt: 25701ms
Fast ulong sqrt: 121126ms
Not much difference. :)
Homepage: omeg.pl email:
Homepage: www.onemanmmo.com email:one at onemanmmo dot com