Skip to content

Update benchmark code from NumPy #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions benchmarks/numpy/bench_lib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Benchmarks for `numpy.lib`."""


from __future__ import absolute_import, division, print_function

from .common import Benchmark

import cupy as np

from benchmarks.utils import sync


@sync
class Pad(Benchmark):
"""Benchmarks for `numpy.pad`."""

param_names = ["shape", "pad_width", "mode"]
params = [
[(1000,), (10, 100), (10, 10, 10)],
[1, 3, (0, 5)],
["constant", "edge", "linear_ramp", "mean", "reflect", "wrap"],
]

def setup(self, shape, pad_width, mode):
self.array = np.empty(shape)

def time_pad(self, shape, pad_width, mode):
np.pad(self.array, pad_width, mode)
16 changes: 16 additions & 0 deletions benchmarks/numpy/bench_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,19 @@ def time_randint_slow(self, name):
high = self.high[name]
np.random.randint(0, high + 1, size=10**5, dtype=name)


@sync
class Permutation(Benchmark):
def setup(self):
self.n = 10000
self.a_1d = np.random.random_sample(self.n)
self.a_2d = np.random.random_sample((self.n, 2))

def time_permutation_1d(self):
np.random.permutation(self.a_1d)

def time_permutation_2d(self):
np.random.permutation(self.a_2d)

def time_permutation_int(self):
np.random.permutation(self.n)
20 changes: 11 additions & 9 deletions benchmarks/numpy/bench_ufunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@
'bitwise_or', 'bitwise_xor', 'cbrt', 'ceil', 'conj', 'conjugate',
'copysign', 'cos', 'cosh', 'deg2rad', 'degrees', 'divide', 'divmod',
'equal', 'exp', 'exp2', 'expm1', 'fabs', 'float_power', 'floor',
'floor_divide', 'fmax', 'fmin', 'fmod', 'frexp', 'greater',
'greater_equal', 'heaviside', 'hypot', 'invert', 'isfinite', 'isinf',
'isnan', 'isnat', 'ldexp', 'left_shift', 'less', 'less_equal', 'log',
'log10', 'log1p', 'log2', 'logaddexp', 'logaddexp2', 'logical_and',
'logical_not', 'logical_or', 'logical_xor', 'maximum', 'minimum',
'mod', 'modf', 'multiply', 'negative', 'nextafter', 'not_equal',
'positive', 'power', 'rad2deg', 'radians', 'reciprocal', 'remainder',
'right_shift', 'rint', 'sign', 'signbit', 'sin', 'sinh', 'spacing',
'sqrt', 'square', 'subtract', 'tan', 'tanh', 'true_divide', 'trunc']
'floor_divide', 'fmax', 'fmin', 'fmod', 'frexp', 'gcd', 'greater',
'greater_equal', 'heaviside', 'hypot', 'invert', 'isfinite',
'isinf', 'isnan', 'isnat', 'lcm', 'ldexp', 'left_shift', 'less',
'less_equal', 'log', 'log10', 'log1p', 'log2', 'logaddexp',
'logaddexp2', 'logical_and', 'logical_not', 'logical_or',
'logical_xor', 'maximum', 'minimum', 'mod', 'modf', 'multiply',
'negative', 'nextafter', 'not_equal', 'positive', 'power',
'rad2deg', 'radians', 'reciprocal', 'remainder', 'right_shift',
'rint', 'sign', 'signbit', 'sin', 'sinh', 'spacing', 'sqrt',
'square', 'subtract', 'tan', 'tanh', 'true_divide', 'trunc']


for name in dir(np):
if isinstance(getattr(np, name, None), np.ufunc) and name not in ufuncs:
Expand Down