summaryrefslogtreecommitdiff
path: root/benchmarks
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2020-06-04 08:30:11 +0300
committerGitHub <noreply@github.com>2020-06-04 08:30:11 +0300
commit924cbe4dadcabd337a6d8b0ef6efa3091a3ed5fc (patch)
tree0b31620582f05ed94b3390427575586105d0a5a9 /benchmarks
parent489de42a9585615ca9962a83882896069357ab97 (diff)
parentebb4e48f83bbbc6cea3c5781a838b032e120663d (diff)
downloadnumpy-924cbe4dadcabd337a6d8b0ef6efa3091a3ed5fc.tar.gz
Merge pull request #16389 from seberg/hardcode-scalar-buffers
ENH: Hardcode buffer handling for simple scalars
Diffstat (limited to 'benchmarks')
-rw-r--r--benchmarks/benchmarks/bench_scalar.py33
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))))))))))
+