diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2020-05-26 17:28:14 -0500 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2020-05-26 17:45:15 -0500 |
commit | 426b3cac7932289f24be7dc6dba6197a4d65740b (patch) | |
tree | e645b4e1acfb70f1c647e3d4df9bbe734a37b467 /benchmarks | |
parent | e4894aef5c93c845081388818a2eb4264c5e1d72 (diff) | |
download | numpy-426b3cac7932289f24be7dc6dba6197a4d65740b.tar.gz |
BENCH: Add simple scalar math benchmarks
Diffstat (limited to 'benchmarks')
-rw-r--r-- | benchmarks/benchmarks/bench_scalar.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/benchmarks/benchmarks/bench_scalar.py b/benchmarks/benchmarks/bench_scalar.py new file mode 100644 index 000000000..219e48bed --- /dev/null +++ b/benchmarks/benchmarks/bench_scalar.py @@ -0,0 +1,33 @@ +from .common import Benchmark, TYPES1 + +import numpy as np + + +class ScalarMath(Benchmark): + # Test scalar math, note that each of these is run repeatedly to offset + # the function call overhead to some degree. + params = [TYPES1] + param_names = ["type"] + def setup(self, typename): + self.num = np.dtype(typename).type(2) + + def time_addition(self, typename): + n = self.num + res = n + n + n + n + n + n + n + n + n + n + + def time_addition_pyint(self, typename): + n = self.num + res = n + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + + def time_multiplication(self, typename): + n = self.num + res = n * n * n * n * n * n * n * n * n * n + + def time_power_of_two(self, typename): + n = self.num + res = n**2, n**2, n**2, n**2, n**2, n**2, n**2, n**2, n**2, n**2 + + def time_abs(self, typename): + n = self.num + res = abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(n)))))))))) + |