In an app I\'m profiling, I found that in some scenarios this function is able to take over 10% of total execution time.
I\'ve seen discussion over the years of fast
You're very likely to gain more speed improvements by changing your algorithms than by changing their implementations: Try to call sqrt()
less instead of making calls faster. (And if you think this isn't possible - the improvements for sqrt()
you mention are just that: improvements of the algorithm used to calculate a square root.)
Since it is used very often, it is likely that your standard library's implementation of sqrt()
is nearly optimal for the general case. Unless you have a restricted domain (e.g., if you need less precision) where the algorithm can take some shortcuts, it's very unlikely someone comes up with an implementation that's faster.
Note that, since that function uses 10% of your execution time, even if you manage to come up with an implementation that only takes 75% of the time of std::sqrt()
, this still will only bring your execution time down by 2,5%. For most applications users wouldn't even notice this, except if they use a watch to measure.