Skip to content

Commit ec38233

Browse files
authored
Merge pull request numpy#26212 from r-devulap/bench-pow
BENCH: Add benchmarks for np.power(x,2) and np.power(x,0.5)
2 parents e43de40 + 6ac0f2d commit ec38233

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

benchmarks/benchmarks/bench_ufunc.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -559,21 +559,22 @@ def time_add_reduce_arg_parsing(self, arg_pack):
559559
np.add.reduce(*arg_pack.args, **arg_pack.kwargs)
560560

561561
class BinaryBench(Benchmark):
562-
def setup(self):
562+
params = [np.float32, np.float64]
563+
param_names = ['dtype']
564+
565+
def setup(self, dtype):
563566
N = 1000000
564-
self.a32 = np.random.rand(N).astype(np.float32)
565-
self.b32 = np.random.rand(N).astype(np.float32)
566-
self.a64 = np.random.rand(N).astype(np.float64)
567-
self.b64 = np.random.rand(N).astype(np.float64)
567+
self.a = np.random.rand(N).astype(dtype)
568+
self.b = np.random.rand(N).astype(dtype)
568569

569-
def time_pow_32(self):
570-
np.power(self.a32, self.b32)
570+
def time_pow(self, dtype):
571+
np.power(self.a, self.b)
571572

572-
def time_pow_64(self):
573-
np.power(self.a64, self.b64)
573+
def time_pow_2(self, dtype):
574+
np.power(self.a, 2.0)
574575

575-
def time_atan2_32(self):
576-
np.arctan2(self.a32, self.b32)
576+
def time_pow_half(self, dype):
577+
np.power(self.a, 0.5)
577578

578-
def time_atan2_64(self):
579-
np.arctan2(self.a64, self.b64)
579+
def time_atan2(self, dtype):
580+
np.arctan2(self.a, self.b)

0 commit comments

Comments
 (0)