tests
This commit is contained in:
parent
a7d391554b
commit
b5ca9615bc
2 changed files with 94 additions and 0 deletions
40
disttest.py
Normal file
40
disttest.py
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
from random import randint
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
def dist1(loc, other_loc):
|
||||||
|
return (loc[0]-other_loc[0])**2 + (loc[1]-other_loc[1])**2 + (loc[2]-other_loc[2])**2
|
||||||
|
|
||||||
|
def yield_pts(n):
|
||||||
|
|
||||||
|
for i in range(0,n):
|
||||||
|
p1 = (10000-randint(0,20000), 10000-randint(0,20000), 10000-randint(0,20000))
|
||||||
|
p2 = (10000-randint(0,20000), 10000-randint(0,20000), 10000-randint(0,20000))
|
||||||
|
|
||||||
|
yield p1, p2
|
||||||
|
|
||||||
|
|
||||||
|
def native(ptlst):
|
||||||
|
return [dist1(p[0], p[1]) for p in ptlst]
|
||||||
|
|
||||||
|
def fast(x1s, y1s, z1s, x2s, y2s, z2s):
|
||||||
|
|
||||||
|
p1 = np.array([x1s, y1s, z1s])
|
||||||
|
p2 = np.array([x2s, y2s, z2s])
|
||||||
|
|
||||||
|
squared_dist = np.sum((p1-p2)**2, axis=0)
|
||||||
|
return np.sqrt(squared_dist)
|
||||||
|
|
||||||
|
import cProfile
|
||||||
|
|
||||||
|
ptlst = [(p1, p2) for (p1, p2) in yield_pts(41000*5*10)]
|
||||||
|
cProfile.runctx("native(ptlst)", globals(), locals())
|
||||||
|
|
||||||
|
|
||||||
|
n=41000*5*10
|
||||||
|
x1s = [10000-randint(0,20000) for i in range(0, n)]
|
||||||
|
y1s = [10000-randint(0,20000) for i in range(0, n)]
|
||||||
|
z1s = [10000-randint(0,20000) for i in range(0, n)]
|
||||||
|
x2s = [10000-randint(0,20000) for i in range(0, n)]
|
||||||
|
y2s = [10000-randint(0,20000) for i in range(0, n)]
|
||||||
|
z2s = [10000-randint(0,20000) for i in range(0, n)]
|
||||||
|
cProfile.runctx("fast(x1s, y1s, z1s, x2s, y2s, z2s)", globals(), locals())
|
||||||
54
sintest.py
Normal file
54
sintest.py
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
import math
|
||||||
|
|
||||||
|
def cutsin(t, freq):
|
||||||
|
|
||||||
|
tF = t * freq
|
||||||
|
ftF = int(t * freq)
|
||||||
|
|
||||||
|
return math.sin(2*math.pi*(tF - ftF))
|
||||||
|
|
||||||
|
def normsin(t, freq):
|
||||||
|
|
||||||
|
return math.sin(2*math.pi*freq*t)
|
||||||
|
|
||||||
|
def cs(x):
|
||||||
|
|
||||||
|
return math.sin(2*math.pi*(x - int(x)))
|
||||||
|
|
||||||
|
def s(x):
|
||||||
|
|
||||||
|
return math.sin(2*math.pi*x)
|
||||||
|
|
||||||
|
|
||||||
|
print(cs(787876879))
|
||||||
|
print(s(787876879))
|
||||||
|
4/0
|
||||||
|
freq = 100
|
||||||
|
t = 7768.878676
|
||||||
|
|
||||||
|
print(normsin(t, freq))
|
||||||
|
print(cutsin(t, freq))
|
||||||
|
|
||||||
|
|
||||||
|
print(t - int(t*freq)/float(freq))
|
||||||
|
print(f'F = {freq}')
|
||||||
|
print(f'TF = {t*freq}')
|
||||||
|
print(f'fTF = {int(t*freq)}')
|
||||||
|
print(f'fTF/F = {int(t*freq)/float(freq)}')
|
||||||
|
"""
|
||||||
|
|
||||||
|
import cProfile
|
||||||
|
|
||||||
|
def dvd():
|
||||||
|
for i in range(0,1000000):
|
||||||
|
normsin(t, freq)
|
||||||
|
|
||||||
|
def snn():
|
||||||
|
for i in range(0,1000000):
|
||||||
|
cutsin(t, freq)
|
||||||
|
|
||||||
|
|
||||||
|
cProfile.runctx("dvd()", globals(), locals())
|
||||||
|
cProfile.runctx("snn()", globals(), locals())
|
||||||
|
|
||||||
|
"""
|
||||||
Loading…
Add table
Reference in a new issue