Skip to content

BENCH: indexing_engines #43916

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

Merged
merged 1 commit into from
Oct 7, 2021
Merged
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
46 changes: 35 additions & 11 deletions asv_bench/benchmarks/indexing_engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,49 @@ class NumericEngineIndexing:
params = [
_get_numeric_engines(),
["monotonic_incr", "monotonic_decr", "non_monotonic"],
[True, False],
[10 ** 5, 2 * 10 ** 6], # 2e6 is above SIZE_CUTOFF
]
param_names = ["engine_and_dtype", "index_type"]
param_names = ["engine_and_dtype", "index_type", "unique", "N"]

def setup(self, engine_and_dtype, index_type):
def setup(self, engine_and_dtype, index_type, unique, N):
engine, dtype = engine_and_dtype
N = 10 ** 5
values = list([1] * N + [2] * N + [3] * N)
arr = {
"monotonic_incr": np.array(values, dtype=dtype),
"monotonic_decr": np.array(list(reversed(values)), dtype=dtype),
"non_monotonic": np.array([1, 2, 3] * N, dtype=dtype),
}[index_type]

if index_type == "monotonic_incr":
if unique:
arr = np.arange(N * 3, dtype=dtype)
else:
values = list([1] * N + [2] * N + [3] * N)
arr = np.array(values, dtype=dtype)
elif index_type == "monotonic_decr":
if unique:
arr = np.arange(N * 3, dtype=dtype)[::-1]
else:
values = list([1] * N + [2] * N + [3] * N)
arr = np.array(values, dtype=dtype)[::-1]
else:
assert index_type == "non_monotonic"
if unique:
arr = np.empty(N * 3, dtype=dtype)
arr[:N] = np.arange(N * 2, N * 3, dtype=dtype)
arr[N:] = np.arange(N * 2, dtype=dtype)
else:
arr = np.array([1, 2, 3] * N, dtype=dtype)

self.data = engine(arr)
# code belows avoids populating the mapping etc. while timing.
self.data.get_loc(2)

def time_get_loc(self, engine_and_dtype, index_type):
self.data.get_loc(2)
self.key_middle = arr[len(arr) // 2]
self.key_early = arr[2]

def time_get_loc(self, engine_and_dtype, index_type, unique, N):
self.data.get_loc(self.key_early)

def time_get_loc_near_middle(self, engine_and_dtype, index_type, unique, N):
# searchsorted performance may be different near the middle of a range
# vs near an endpoint
self.data.get_loc(self.key_middle)


class ObjectEngineIndexing:
Expand Down