Fast Square Root For Distance Calculations?

Started by
12 comments, last by Kylotan 7 years, 8 months ago

Thanks for info! Well, yeah... Final project will be written in C++. I was just hoping to write the code for Blender Game Engine. In my case the map() won't work because my for loop looks near like this:


for j in self.joints:
    o1 = j.object1
    o2 = j.object2
    j.integrate(o1, o2)

# j is a class, j.object1 and j.object2 are classes, integrate(self, o1, o2) is a function inside j class
class j:
    ...some stuff here...
    def integrate(o1, o2):
        distance = (o1.position - o2.position).magnitude
        ...more stuff here...

This is how the code looks, more or less...

Advertisement

Try inlining the integrate code into the for loop. Function calls in Python are pretty slow.

um... Welll... The integrate function calls one more function several times at one position. And if I wrote it all inside the code - it'd make the code a huge mess + I doubt it would be any faster. But you wanna tell that OOP + Python = slow?

I said nothing about OOP, just that Python function calls are relatively slow. If you can inline that code, it will run a little faster.

This topic is closed to new replies.

Advertisement