From 318c47032f5e93cddda4b7fc024a3a86ce08c0b8 Mon Sep 17 00:00:00 2001 From: Oli Date: Sat, 22 Jan 2022 18:51:06 -0300 Subject: [PATCH 1/3] add perf test --- tests/performance/generation/time.py | 56 ++++++++++++++++++++++++++++ tests/stages/generation/test.py | 13 ++++--- tests/utils/gen_sample.py | 32 ++++++++++++++++ 3 files changed, 95 insertions(+), 6 deletions(-) create mode 100644 tests/performance/generation/time.py create mode 100644 tests/utils/gen_sample.py diff --git a/tests/performance/generation/time.py b/tests/performance/generation/time.py new file mode 100644 index 0000000..7b13400 --- /dev/null +++ b/tests/performance/generation/time.py @@ -0,0 +1,56 @@ +import numpy as np +#from tests.utils.gen_sample import generate + +import sys + +from FFTMA import gen +import time + +def generate(N): + start_time = time.time() + nx, ny, nz = N,N,N + dx, dy, dz = 1.0, 1.0, 1.0 + seed= 1548762 #rdi(10000,99999) + var=1 + vario=2 + alpha=1 + lcx=2 + lcy=4 + lcz=16 + ap1x=1 + ap1y=0 + ap1z=0 + ap2x=0 + ap2y=1 + ap2z=0 + + v1 = (var, vario, alpha, lcx, lcy, lcz, ap1x, ap1y, ap1z, ap2x, ap2y, ap2z) + variograms = [v1] + + mean=15.3245987 + variance=3.5682389 + typ=3 + + k = gen(nx, ny, nz, dx, dy, dz, seed, variograms, mean, variance, typ) + + duration = time.time() - start_time + return k, duration + +N=int(sys.argv[1]) +SAMPLE_SIZE=1000 + +def time_measurement(n, sample_size): + sample = [] + + for i in range(sample_size): + _, duration = generate(n) + print(i) + sample.append(duration) + + print("sali") + npsample = np.array(sample) + + print(np.mean(npsample)) + print(np.median(npsample)) + +time_measurement(N, SAMPLE_SIZE) \ No newline at end of file diff --git a/tests/stages/generation/test.py b/tests/stages/generation/test.py index 94118b1..732fdf1 100644 --- a/tests/stages/generation/test.py +++ b/tests/stages/generation/test.py @@ -1,6 +1,7 @@ -from FFTMA import gen + import numpy as np import unittest +from FFTMA import gen import time def generate(N): @@ -30,18 +31,18 @@ def generate(N): k = gen(nx, ny, nz, dx, dy, dz, seed, variograms, mean, variance, typ) - print(f"Generation with N = {N} time = {time.time() - start_time}s") - return k - + duration = time.time() - start_time + return k, duration def test(N): - k = generate(N) + k, duration = generate(N) k_correct = np.load(f"out_{N}.npy") comparison = k == k_correct + print(f"Generation with N = {N} time = {duration}s") return comparison.all() class TestGeneration(unittest.TestCase): - def test_8(self): + def test_08(self): self.assertTrue(test(8)) def test_16(self): diff --git a/tests/utils/gen_sample.py b/tests/utils/gen_sample.py new file mode 100644 index 0000000..2c11992 --- /dev/null +++ b/tests/utils/gen_sample.py @@ -0,0 +1,32 @@ +from FFTMA import gen +import time + +def generate(N): + start_time = time.time() + nx, ny, nz = N,N,N + dx, dy, dz = 1.0, 1.0, 1.0 + seed= 1548762 #rdi(10000,99999) + var=1 + vario=2 + alpha=1 + lcx=2 + lcy=4 + lcz=16 + ap1x=1 + ap1y=0 + ap1z=0 + ap2x=0 + ap2y=1 + ap2z=0 + + v1 = (var, vario, alpha, lcx, lcy, lcz, ap1x, ap1y, ap1z, ap2x, ap2y, ap2z) + variograms = [v1] + + mean=15.3245987 + variance=3.5682389 + typ=3 + + k = gen(nx, ny, nz, dx, dy, dz, seed, variograms, mean, variance, typ) + + duration = time.time() - start_time + return k, duration \ No newline at end of file From d3e5479a848c10bf9a38900ca465d32cf42f7b32 Mon Sep 17 00:00:00 2001 From: Oli Date: Sat, 22 Jan 2022 19:44:54 -0300 Subject: [PATCH 2/3] update makefile --- Makefile | 5 ++++- README.md | 16 +++++++++++++++- tests/performance/generation/time.py | 6 +++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 876955e..b4742c9 100644 --- a/Makefile +++ b/Makefile @@ -19,4 +19,7 @@ perf: binaries cd tests/performance && python3 connectivity.py test-gen: fftma - cd tests/stages/generation && python3 -m unittest test.py \ No newline at end of file + cd tests/stages/generation && python3 -m unittest test.py + +time-gen: fftma + cd tests/performance/generation && python3 time.py $(N) \ No newline at end of file diff --git a/README.md b/README.md index f19a670..3ae207a 100644 --- a/README.md +++ b/README.md @@ -18,18 +18,32 @@ make binaries make run ``` -## Correr los casos de prueba +## Pruebas de integración ``` make test ``` +## Pruebas unitarias + +### Generacion + +``` +make test-gen +``` + ## Correr las pruebas de performance ``` make perf ``` +### Obtener tiempos de generacion + +``` +make time-gen N= +``` + ## Instalar el binario FFTMA ``` diff --git a/tests/performance/generation/time.py b/tests/performance/generation/time.py index 7b13400..9721e32 100644 --- a/tests/performance/generation/time.py +++ b/tests/performance/generation/time.py @@ -42,15 +42,15 @@ SAMPLE_SIZE=1000 def time_measurement(n, sample_size): sample = [] + print(f"SAMPLE_SIZE = {SAMPLE_SIZE}") for i in range(sample_size): _, duration = generate(n) print(i) sample.append(duration) - print("sali") npsample = np.array(sample) - print(np.mean(npsample)) - print(np.median(npsample)) + print(f"AVG: {np.mean(npsample)} seconds") + print(f"MEDIAN: {np.median(npsample)} seconds") time_measurement(N, SAMPLE_SIZE) \ No newline at end of file From 286dcf9693775c6a520c4a1effbeb5588f9416e1 Mon Sep 17 00:00:00 2001 From: Oli Date: Thu, 27 Jan 2022 16:58:29 -0300 Subject: [PATCH 3/3] add mem profile from outside --- fftma_module/gen/example.py | 49 +++++++++++++++++---------------- fftma_module/gen/mem_profile.py | 16 +++++++++++ 2 files changed, 42 insertions(+), 23 deletions(-) create mode 100644 fftma_module/gen/mem_profile.py diff --git a/fftma_module/gen/example.py b/fftma_module/gen/example.py index 057c0f5..e2d7652 100644 --- a/fftma_module/gen/example.py +++ b/fftma_module/gen/example.py @@ -2,30 +2,33 @@ from FFTMA import gen import numpy as np import sys -N=int(sys.argv[1]) +def generate(n): + nx, ny, nz = n,n,n + dx, dy, dz = 1.0, 1.0, 1.0 + seed= 1548762 #rdi(10000,99999) + var=1 + vario=2 + alpha=1 + lcx=2 + lcy=4 + lcz=16 + ap1x=1 + ap1y=0 + ap1z=0 + ap2x=0 + ap2y=1 + ap2z=0 -nx, ny, nz = N,N,N -dx, dy, dz = 1.0, 1.0, 1.0 -seed= 1548762 #rdi(10000,99999) -var=1 -vario=2 -alpha=1 -lcx=2 -lcy=4 -lcz=16 -ap1x=1 -ap1y=0 -ap1z=0 -ap2x=0 -ap2y=1 -ap2z=0 + v1 = (var, vario, alpha, lcx, lcy, lcz, ap1x, ap1y, ap1z, ap2x, ap2y, ap2z) + variograms = [v1] -v1 = (var, vario, alpha, lcx, lcy, lcz, ap1x, ap1y, ap1z, ap2x, ap2y, ap2z) -variograms = [v1] + mean=15.3245987 + variance=3.5682389 + typ=3 -mean=15.3245987 -variance=3.5682389 -typ=3 + k=gen(nx, ny, nz, dx, dy, dz, seed, variograms, mean, variance, typ) + np.save(f"out_{n}.npy",k) -k=gen(nx, ny, nz, dx, dy, dz, seed, variograms, mean, variance, typ) -np.save(f"out_{N}.npy",k) \ No newline at end of file +if __name__ == '__main__': + N=int(sys.argv[1]) + generate(N) \ No newline at end of file diff --git a/fftma_module/gen/mem_profile.py b/fftma_module/gen/mem_profile.py new file mode 100644 index 0000000..55d5cba --- /dev/null +++ b/fftma_module/gen/mem_profile.py @@ -0,0 +1,16 @@ +from sympy import N +from example import generate + +from memory_profiler import memory_usage + +from memory_profiler import memory_usage +import sys + +if __name__ == '__main__': + N=int(sys.argv[1]) + + def run_gen(): + generate(N) + + mem_usage = memory_usage(run_gen) + print('Maximum memory usage: %s' % max(mem_usage)) \ No newline at end of file