pycompact - added performance benchmark test

This commit is contained in:
ignis 2021-08-12 07:30:48 +09:00
parent f2486bfa97
commit 7f6df479c1

View file

@ -557,6 +557,106 @@ def validate_trigonometric():
def performance_benchmark():
import time
writeToFile = False
shape = (256, 256, 512)
nz, ny, nx = shape
pi8 = np.arccos(-1.)
l_0 = 2.0
hyp=l_0*pi8/ny
hxp=hyp
hzp=hyp
cs = CompactScheme(nx, ny, nz, False, True, True, 4., 2., 2.)
print ("Test ddx")
Y1 = np.zeros(shape)
true = np.zeros(shape)
XX = np.arange(nx) * hxp
YY = np.arange(ny) * hyp
ZZ = np.arange(nz) * hzp
print ("3-D trigonometric test")
zz, yy, xx = np.meshgrid(ZZ, YY, XX, indexing='ij')
def compare_3d_result (true1, dY1):
print ("Calculated Min/Max", dY1.min(), dY1.max())
print ("True Min/Max", true1.min(), true1.max())
eps = np.finfo(true1.dtype).eps
relerr = (dY1 - true1) / (true1 + eps)
print ("Relative Error", np.nanmin(relerr), np.nanmax(relerr))
Y1[:] = np.sin(1.1 * xx) * np.sin(3.0 * yy) * np.sin(2.0 * zz)[:]
print(" DDX Test ")
true[:] = (1.1 * np.cos(1.1 * xx) * np.sin(3.0 * yy) * np.sin(2.0 * zz))[:]
t0 = time.perf_counter()
for i in range(100):
dY1 = cs.ddx(Y1)[:]
t1 = time.perf_counter()
print ("Elapsed time in sec for 100 repetition: ", t1-t0)
compare_3d_result(true, dY1)
print("D2DX Test ")
true[:] = (- 1.1 * 1.1 * np.sin(1.1 * xx) * np.sin(3.0 * yy) * np.sin(2.0 * zz))[:]
t0 = time.perf_counter()
for i in range(100):
dY1 = cs.d2dx(Y1)[:]
t1 = time.perf_counter()
print ("Elapsed time in sec for 100 repetition: ", t1-t0)
compare_3d_result(true, dY1)
print(" DDY Test ")
true[:] = (3.0 * np.sin(1.1 * xx) * np.cos(3.0 * yy) * np.sin(2.0 * zz))[:]
t0 = time.perf_counter()
for i in range(100):
dY1 = cs.ddy(Y1)[:]
t1 = time.perf_counter()
print ("Elapsed time in sec for 100 repetition: ", t1-t0)
compare_3d_result(true, dY1)
print(" D2DY Test ")
true[:] = (-3. * 3.0 * np.sin(1.1 * xx) * np.sin(3.0 * yy) * np.sin(2.0 * zz))[:]
t0 = time.perf_counter()
for i in range(100):
dY1 = cs.d2dy(Y1)[:]
t1 = time.perf_counter()
print ("Elapsed time in sec for 100 repetition: ", t1-t0)
compare_3d_result(true, dY1)
print(" DDZ Test ")
true[:] = (2.0 * np.sin(1.1 * xx) * np.sin(3.0 * yy) * np.cos(2.0 * zz))[:]
t0 = time.perf_counter()
for i in range(100):
dY1 = cs.ddz(Y1)[:]
t1 = time.perf_counter()
print ("Elapsed time in sec for 100 repetition: ", t1-t0)
compare_3d_result(true, dY1)
print(" D2DZ Test ")
Y1[:] = np.sin(1.1 * xx) * np.sin(3.0 * yy) * np.sin(2.0 * zz)[:]
true[:] = (-2. * 2.0 * np.sin(1.1 * xx) * np.sin(3.0 * yy) * np.sin(2.0 * zz))[:]
t0 = time.perf_counter()
for i in range(100):
dY1 = cs.d2dz(Y1)[:]
t1 = time.perf_counter()
print ("Elapsed time in sec for 100 repetition: ", t1-t0)
compare_3d_result(true, dY1)
def test_dns_data(): def test_dns_data():
import sys import sys
@ -608,6 +708,11 @@ if __name__ == "__main__":
exit(-1) exit(-1)
if testname == "perf":
print("Performance Benchmark Test")
performance_benchmark()
if testname == "tri": if testname == "tri":
print("Trigonometric Function Test") print("Trigonometric Function Test")
validate_trigonometric() validate_trigonometric()