Skip to content
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

test: Adapt benchmarks to use codspeed #741

Merged
merged 16 commits into from
Aug 12, 2024
Merged
Changes from 9 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
97 changes: 97 additions & 0 deletions benchmarks/test_benchmark_coo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@
SEED = 42
DeaMariaLeon marked this conversation as resolved.
Show resolved Hide resolved


def side_ids(side):
return f"{side=}"


@pytest.mark.parametrize("side", [100, 500, 1000], ids=side_ids)
def test_matmul(benchmark, side):
rng = np.random.default_rng(seed=SEED)
x = sparse.random((side, side), density=DENSITY, random_state=rng)
y = sparse.random((side, side), density=DENSITY, random_state=rng)

x @ y # Numba compilation

@benchmark
def bench():
x @ y


def elemwise_test_name(param):
side, rank = param
return f"{side=}-{rank=}"
Expand All @@ -36,3 +53,83 @@ def test_elemwise(benchmark, f, elemwise_args):
@benchmark
def bench():
f(x, y)


@pytest.fixture(scope="module", params=[100, 500, 1000], ids=side_ids)
def elemwise_broadcast_args(request):
side = request.param
rng = np.random.default_rng(seed=SEED)
if side**side >= 2**26:
pytest.skip()
x = sparse.random((side, 1, side), density=DENSITY, random_state=rng)
y = sparse.random((side, side), density=DENSITY, random_state=rng)
return x, y


@pytest.mark.parametrize("f", [operator.add, operator.mul])
def test_elemwise_broadcast_args(benchmark, f, elemwise_broadcast_args):
x, y = elemwise_broadcast_args
f(x, y)

@benchmark
def bench():
f(x, y)


@pytest.fixture(scope="module", params=[100, 500, 1000], ids=side_ids)
def indexing_args(request):
side = request.param
rng = np.random.default_rng(seed=SEED)
if side**side >= 2**26:
pytest.skip()

x = sparse.random((side, side, side), density=0.01, random_state=rng)

# Numba compilation
x[5]
DeaMariaLeon marked this conversation as resolved.
Show resolved Hide resolved

return x, side
DeaMariaLeon marked this conversation as resolved.
Show resolved Hide resolved


def time_index_scalar(benchmark, indexing_args):
x, side = indexing_args

@benchmark
def bench():
x[side / 2, side / 2, side / 2]
DeaMariaLeon marked this conversation as resolved.
Show resolved Hide resolved


def time_index_slice(benchmark, indexing_args):
x, side = indexing_args

@benchmark
def bench():
x[: side / 2]


def time_index_slice2(benchmark, indexing_args):
x, side = indexing_args

@benchmark
def bench():
x[: side / 2, : side / 2]


def time_index_slice3(benchmark, indexing_args):
x, side = indexing_args

@benchmark
def bench():
x[: side / 2, : side / 2, : side / 2]


def time_index_fancy(benchmark, indexing_args):
x, side = indexing_args
rng = np.random.default_rng(seed=SEED)
index = rng.integers(0, side, int(side / 2))

x[index] # Numba compilation

@benchmark
def bench():
x[index]
Loading