Skip to content

Commit 9078d30

Browse files
committed
add benchmark for np.clip
1 parent 65aa836 commit 9078d30

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

benchmarks/benchmarks/bench_clip.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from .common import Benchmark
2+
3+
import numpy as np
4+
5+
6+
class ClipFloat(Benchmark):
7+
param_names = ["dtype", "size"]
8+
params = [
9+
[np.float32, np.float64, np.longdouble],
10+
[100, 100_000]
11+
]
12+
13+
def setup(self, dtype, size):
14+
rng = np.random.default_rng()
15+
self.array = rng.random(size=size).astype(dtype)
16+
self.dataout = np.full_like(self.array, 0.5)
17+
18+
def time_clip(self, dtype, size):
19+
np.clip(self.array, 0.125, 0.875, self.dataout)
20+
21+
22+
class ClipInteger(Benchmark):
23+
param_names = ["dtype", "size"]
24+
params = [
25+
[np.int32, np.int64],
26+
[100, 100_000]
27+
]
28+
29+
def setup(self, dtype, size):
30+
rng = np.random.default_rng()
31+
self.array = rng.integers(256, size=size, dtype=dtype)
32+
self.dataout = np.full_like(self.array, 128)
33+
34+
def time_clip(self, dtype, size):
35+
np.clip(self.array, 32, 224, self.dataout)

0 commit comments

Comments
 (0)