Benchmarks added

This commit is contained in:
Fabian Joswig 2021-10-26 10:20:47 +01:00
parent 8655fe2cd1
commit b5f3dd6ac3
9 changed files with 58 additions and 1 deletions

55
tests/benchmark_test.py Normal file
View file

@ -0,0 +1,55 @@
import numpy as np
import pyerrors as pe
import pytest
import time
np.random.seed(0)
def test_bench_mul(benchmark):
length = 1000
my_obs = pe.Obs([np.random.rand(length)], ['t1'])
def mul(x, y):
return x * y
benchmark(mul, my_obs, my_obs)
def test_bench_cmul(benchmark):
length = 1000
my_obs = pe.CObs(pe.Obs([np.random.rand(length)], ['t1']),
pe.Obs([np.random.rand(length)], ['t1']))
def mul(x, y):
return x * y
benchmark(mul, my_obs, my_obs)
def test_bench_matmul(benchmark):
dim = 4
my_list = []
length = 1000
for i in range(dim ** 2):
my_list.append(pe.Obs([np.random.rand(length)], ['t1']))
my_array = np.array(my_list).reshape((dim, dim))
benchmark(pe.linalg.matmul, my_array, my_array)
def test_bench_cmatmul(benchmark):
dim = 4
my_list = []
length = 1000
for i in range(dim ** 2):
my_list.append(pe.CObs(pe.Obs([np.random.rand(length)], ['t1']),
pe.Obs([np.random.rand(length)], ['t1'])))
my_array = np.array(my_list).reshape((dim, dim))
benchmark(pe.linalg.matmul, my_array, my_array)
def test_bench_gamma_method(benchmark):
length = 1000
my_obs = pe.Obs([np.random.rand(length)], ['t1'])
benchmark(my_obs.gamma_method)