From 68c8f72ba51dc627d0d9c2d7524504fad19d44bf Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sat, 25 May 2024 14:47:10 +0800 Subject: [PATCH] Create vec.py --- benchmarks/vec.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 benchmarks/vec.py diff --git a/benchmarks/vec.py b/benchmarks/vec.py new file mode 100644 index 00000000..fbb959d4 --- /dev/null +++ b/benchmarks/vec.py @@ -0,0 +1,23 @@ +import sys + +is_cpython = hasattr(sys, 'getrefcount') + +if is_cpython: + class vec2: + def __init__(self, x, y): + self.x = x + self.y = y + + def __add__(self, other): + return vec2(self.x + other.x, self.y + other.y) + + def __eq__(self, other): + return self.x == other.x and self.y == other.y +else: + from linalg import vec2 + +x = vec2(0, 0) +for i in range(10000000): + x += vec2(1, 1) + +assert x == vec2(5000000, 5000000)