summaryrefslogtreecommitdiff
path: root/benchmarks
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2016-01-07 17:53:21 -0700
committerCharles Harris <charlesr.harris@gmail.com>2016-01-07 19:19:25 -0700
commit931e2d1e8ba3fd6b129a6d74e3a1ad9984c1938a (patch)
treec52b08e903820f15b52dcbf215cc7f340f575e15 /benchmarks
parent8a76291c76aa9b33b18ceb06f6e8f37f990c9e27 (diff)
downloadnumpy-931e2d1e8ba3fd6b129a6d74e3a1ad9984c1938a.tar.gz
ENH: Add benchmark tests for numpy.random.randint.
This add benchmarks randint. There is one set of benchmarks for the default dtype, 'l', that can be tracked back, and another set for the new dtypes 'bool', 'uint8', 'uint16', 'uint32', and 'uint64'.
Diffstat (limited to 'benchmarks')
-rw-r--r--benchmarks/benchmarks/bench_random.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/benchmarks/benchmarks/bench_random.py b/benchmarks/benchmarks/bench_random.py
index a3c3566b0..18444b9a1 100644
--- a/benchmarks/benchmarks/bench_random.py
+++ b/benchmarks/benchmarks/bench_random.py
@@ -3,6 +3,7 @@ from __future__ import absolute_import, division, print_function
from .common import Benchmark
import numpy as np
+from numpy.lib import NumpyVersion
class Random(Benchmark):
@@ -27,3 +28,40 @@ class Shuffle(Benchmark):
def time_100000(self):
np.random.shuffle(self.a)
+
+
+class Randint(Benchmark):
+
+ def time_randint_fast(self):
+ """Compare to uint32 below"""
+ np.random.randint(0, 2**30, size=10**5)
+
+ def time_randint_slow(self):
+ """Compare to uint32 below"""
+ np.random.randint(0, 2**30 + 1, size=10**5)
+
+
+class Randint_dtype(Benchmark):
+ high = {
+ 'bool': 1,
+ 'uint8': 2**7,
+ 'uint16': 2**15,
+ 'uint32': 2**31,
+ 'uint64': 2**63
+ }
+
+ param_names = ['dtype']
+ params = ['bool', 'uint8', 'uint16', 'uint32', 'uint64']
+
+ def setup(self, name):
+ if NumpyVersion(np.__version__) < '1.11.0.dev0':
+ raise NotImplementedError
+
+ def time_randint_fast(self, name):
+ high = self.high[name]
+ np.random.randint(0, high, size=10**5, dtype=name)
+
+ def time_randint_slow(self, name):
+ high = self.high[name]
+ np.random.randint(0, high + 1, size=10**5, dtype=name)
+