8000 MAINT: Don't always make full copies in (arg)searchsorted. by ewmoore · Pull Request #16942 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MAINT: Don't always make full copies in (arg)searchsorted. #16942

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 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
BENCH: Add benchmark for searchsorted
  • Loading branch information
ewmoore committed Jul 24, 2020
commit 3817dc85245aa43ea622e808841c156f30f7c5a3
24 changes: 24 additions & 0 deletions benchmarks/benchmarks/bench_function_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,27 @@ def time_2(self):

def time_2_broadcast(self):
np.where(self.cond, self.d, 0)

class SearchSorted(Benchmark):
params = [[1, 10, 100, 1000, 10000, 100000],
[10, 1000, 10000, 100000, 1000000],
['sorted', 'random'],
[('f8', 'f8'), ('i8', 'i8'), ('i4', 'i8'), ('i8', 'i4'), ('i4', 'u4')],]

param_names = ['needlesize', 'haystacksize', 'needletype', 'dtype']

def setup(self, needlesize, haystacksize, needletype, dtype):
self.random = np.random.RandomState(3333).random_integers(0, haystacksize, needlesize).astype(dtype[1])
self.sorted = np.sort(self.random)
if needletype == 'sorted':
self.needle = self.sorted
else:
self.needle = self.random
self.haystack = np.arange(haystacksize, dtype=dtype[0])
self.sorter = np.arange(haystacksize, dtype=np.intp)

def time_searchsorted(self, *args):
self.haystack.searchsorted(self.needle)

def time_argsearchsorted(self, *args):
self.haystack.searchsorted(self.needle, sorter=self.sorter)
0