From 8b2b2a9c3482d073b28c08e7575638cdec3f9ff5 Mon Sep 17 00:00:00 2001 From: Crizomb <62544756+Crizomb@users.noreply.github.com> Date: Wed, 15 Feb 2023 13:38:55 +0100 Subject: [PATCH] increasing performances explicit for loop instead of sum in Node.get_force --- barnes-hut-galaxy-new.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/barnes-hut-galaxy-new.py b/barnes-hut-galaxy-new.py index b6de01b..939ee35 100644 --- a/barnes-hut-galaxy-new.py +++ b/barnes-hut-galaxy-new.py @@ -117,7 +117,13 @@ class Node: if self.is_external or self.width*self.width / dist_squared < THETA_SQUARED: return newton_law(self.mass, star.mass, self.center - star.pos) else: - return sum((child.get_force(star) for child in self.children), Vec3.zero()) + acc = Vec3.zero() + for child in self.children: + acc += child.get_force(star) + return acc + + #return sum((child.get_force(star) for child in self.children), Vec3.zero()) #slower + """Init simulation"""