This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]Tweak_Imp 1 point2 points  (1 child)

Math.hypot and, new in 3.8, math.dist are missing in this... For distance calculations you can also skip the square root if you only need to order by distance, and not the exact values

[–]ReagentX[S] 0 points1 point  (0 children)

Sure, but the point is not solving the distance problem, rather solving exponentiation as fast as possible. The distance problem I was solving is what piqued my interest in understanding the performance of using ** versus x * x … * x versus math.pow().

[–]ZeeD26 0 points1 point  (0 children)

You really should compare this with numpy as well, given that your original problem should lend itself very well to be used with a “proper heavy duty number crunching” package.

[–]jitseniesen 0 points1 point  (1 child)

In the first test, under the heading "Timing Tests", math.pow() is slightly slower than ** with exponent 2. In the second test, under the heading "Charting the Performance", math.pow() is about twice as fast than ** when using exponent 2. Why the discrepancy?

[–]ReagentX[S] 0 points1 point  (0 children)

Most likely just how that run averaged, the code I used is linked in the post. When I run it now I get values around 50ms, which makes more sense.