Skip to content

Commit

Permalink
Merge pull request numpy#12723 from jakirkham/inc_other_sort_benchmarks
Browse files Browse the repository at this point in the history
BENCH: Expand sort benchmarks
  • Loading branch information
mattip authored Jan 13, 2019
2 parents c9d3330 + c61bf95 commit 5af5244
Showing 1 changed file with 30 additions and 19 deletions.
49 changes: 30 additions & 19 deletions benchmarks/benchmarks/bench_function_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,35 +96,46 @@ def time_select_larger(self):


class Sort(Benchmark):
def setup(self):
self.e = np.arange(10000, dtype=np.float32)
self.o = np.arange(10001, dtype=np.float32)
params = [
['quick', 'merge', 'heap'],
['float32', 'int32', 'uint32']
]
param_names = ['kind', 'dtype']

def setup(self, kind, dtype):
self.e = np.arange(10000, dtype=dtype)
self.o = np.arange(10001, dtype=dtype)
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)
self.equal = np.ones(10000, dtype=dtype)
self.many_equal = np.sort(np.arange(10000) % 10).astype(dtype)

try:
np.sort(self.e, kind=kind)
except TypeError:
raise NotImplementedError()

def time_sort(self):
np.sort(self.e)
def time_sort(self, kind, dtype):
np.sort(self.e, kind=kind)

def time_sort_random(self):
np.sort(self.o)
def time_sort_random(self, kind, dtype):
np.sort(self.o, kind=kind)

def time_sort_inplace(self):
self.e.sort()
def time_sort_inplace(self, kind, dtype):
self.e.sort(kind=kind)

def time_sort_equal(self):
self.equal.sort()
def time_sort_equal(self, kind, dtype):
self.equal.sort(kind=kind)

def time_sort_many_equal(self):
self.many_equal.sort()
def time_sort_many_equal(self, kind, dtype):
self.many_equal.sort(kind=kind)

def time_argsort(self):
self.e.argsort()
def time_argsort(self, kind, dtype):
self.e.argsort(kind=kind)

def time_argsort_random(self):
self.o.argsort()
def time_argsort_random(self, kind, dtype):
self.o.argsort(kind=kind)


class SortWorst(Benchmark):
Expand Down

0 comments on commit 5af5244

Please sign in to comment.