diff options
author | Julian Taylor <jtaylor.debian@googlemail.com> | 2016-07-27 19:20:54 +0200 |
---|---|---|
committer | Julian Taylor <jtaylor.debian@googlemail.com> | 2016-07-29 21:41:18 +0200 |
commit | afc4f2419a66ee659e0f71f2891573ef612ddd30 (patch) | |
tree | 8dca9a71014b3828cdfc112f61ced697fb575632 /benchmarks | |
parent | 07201420338f87d0a19ec6b5d756f40350e1f21b (diff) | |
download | numpy-afc4f2419a66ee659e0f71f2891573ef612ddd30.tar.gz |
BENCH: add more sort benchmarks
benchmark for random, all equal elements, many equal elements and median
of 3 worst case
Diffstat (limited to 'benchmarks')
-rw-r--r-- | benchmarks/benchmarks/bench_function_base.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/benchmarks/benchmarks/bench_function_base.py b/benchmarks/benchmarks/bench_function_base.py index 35d355ffa..23103ba66 100644 --- a/benchmarks/benchmarks/bench_function_base.py +++ b/benchmarks/benchmarks/bench_function_base.py @@ -71,16 +71,44 @@ class Sort(Benchmark): def setup(self): self.e = np.arange(10000, dtype=np.float32) self.o = np.arange(10001, dtype=np.float32) + np.random.seed(25) + np.random.shuffle(self.o) + # quicksort implementations can have issues with equal elements + self.equal = np.ones(10000) + self.many_equal = np.sort(np.arange(10000) % 10) + + # quicksort median of 3 worst case + self.worst = np.arange(1000000) + x = self.worst + while x.size > 3: + mid = x.size // 2 + x[mid], x[-2] = x[-2], x[mid] + x = x[:-2] def time_sort(self): np.sort(self.e) + def time_sort_random(self): + np.sort(self.o) + def time_sort_inplace(self): self.e.sort() + def time_sort_equal(self): + self.equal.sort() + + def time_sort_many_equal(self): + self.many_equal.sort() + + def time_sort_worst(self): + np.sort(self.worst) + def time_argsort(self): self.e.argsort() + def time_argsort_random(self): + self.o.argsort() + class Where(Benchmark): def setup(self): |