-
-
Save ly29/64ef0392acecbb49d0a2 to your computer and use it in GitHub Desktop.
numpy 2, item wise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from timeit import Timer | |
setup_user = """ | |
from math import sqrt | |
a= [10,11,12] | |
def len_user(v): | |
return sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]) | |
""" | |
setup_vector = """ | |
from mathutils import Vector | |
a= [10,11,12] | |
def len_vec(v): | |
return Vector(v).length | |
""" | |
setup_lambda = """ | |
from mathutils import Vector | |
a= [10,11,12] | |
len_lambda=lambda a:Vector(a).length | |
""" | |
setup_np = """ | |
from numpy.linalg import norm | |
a = [10,11,12] | |
def len_np(v): | |
return norm(v) | |
""" | |
def test(): | |
t1 = Timer("""m = len_user(a)""", setup=setup_user) | |
print("user ", min(t1.repeat(3,100000))) | |
t2 = Timer("""m = len_vec(a)""", setup=setup_vector) | |
print("Vector", min(t2.repeat(3,100000))) | |
t3 = Timer("""m= len_lambda(a)""", setup=setup_lambda) | |
print("Lambda", min(t3.repeat(3,100000))) | |
t4 = Timer("""m = len_np(a)""", setup=setup_np) | |
print("Numpy ", min(t4.repeat(3,100000))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
blender console