pyerrors/tests/benchmark_test.py

49 lines
1.1 KiB
Python
Raw Normal View History

2021-10-26 10:20:47 +01:00
import numpy as np
import pyerrors as pe
import pytest
np.random.seed(0)
2021-10-26 10:41:36 +01:00
length = 1000
def mul(x, y):
return x * y
2021-10-26 10:20:47 +01:00
2021-10-26 10:41:36 +01:00
def test_b_mul(benchmark):
my_obs = pe.Obs([np.random.rand(length)], ['t1'])
2021-10-26 10:20:47 +01:00
benchmark(mul, my_obs, my_obs)
2021-10-26 10:41:36 +01:00
def test_b_cmul(benchmark):
2021-10-26 10:20:47 +01:00
my_obs = pe.CObs(pe.Obs([np.random.rand(length)], ['t1']),
pe.Obs([np.random.rand(length)], ['t1']))
benchmark(mul, my_obs, my_obs)
2021-10-26 10:41:36 +01:00
def test_b_matmul(benchmark):
2021-10-26 10:20:47 +01:00
dim = 4
my_list = []
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)
2021-10-26 10:41:36 +01:00
def test_b_cmatmul(benchmark):
2021-10-26 10:20:47 +01:00
dim = 4
my_list = []
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)
2021-10-26 10:41:36 +01:00
def test_b_gamma(benchmark):
2021-10-26 10:20:47 +01:00
my_obs = pe.Obs([np.random.rand(length)], ['t1'])
benchmark(my_obs.gamma_method)