Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is sqrt still slow in Delphi 2009?

Is sqrt still slow in Delphi 2009?

Are the old tricks (lookup table, approx functions) still useful?

like image 515
Mykelyk Avatar asked Jan 23 '23 14:01

Mykelyk


2 Answers

If you are dealing with a small set of really large numbers then a lookup table will most always be faster. While if you are dealing with a large set of small numbers then even a slow routine may be faster then maintaining a large table.

I looked in System.pas (where SQRT is located) and while there are a number of blocks marked as licensed from the Fastcode project, SQRT is not. In fact, it just makes an assembly call to FSQRT, so it most likely hasn't changed. So if it was comparatively slow at one point then it most likely still is as slow (although your CPU may be a lot faster and optimized for that now . . . .)

My recommendation is to look at your usage and test.

like image 125
Jim McKeeth Avatar answered Jan 31 '23 08:01

Jim McKeeth


Many moons ago I had an app that computed distance to sort vectors. I realized sorting by the un-sqrt-ed values was the same so I skipped it altogether. Sorted by distance^2 and saved some time.

like image 29
n8wrl Avatar answered Jan 31 '23 10:01

n8wrl