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: Benchmark to be run on codspeed #740

Merged
merged 7 commits into from
Aug 8, 2024
Merged
Changes from 2 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
31 changes: 24 additions & 7 deletions benchmarks/test_benchmark_coo.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
import operator

import sparse

import pytest

import numpy as np

DENSITY = 0.01
SEED = 42


@pytest.fixture(scope="module", side=[100, 500, 1000], rank=[1, 2, 3, 4])
DeaMariaLeon marked this conversation as resolved.
Show resolved Hide resolved
def elemwise_args(request):
side, rank = request.side, request.rank
DeaMariaLeon marked this conversation as resolved.
Show resolved Hide resolved
if side**rank >= 2**26:
pytest.skip()
rng = np.random.default_rng(seed=SEED)
shape = (side,) * rank
x = sparse.random(shape, density=DENSITY, random_state=rng)
y = sparse.random(shape, density=DENSITY, random_state=rng)
return x, y

def test_matmul(benchmark):
rng = np.random.default_rng(seed=42)
x = sparse.random((40, 40), density=0.01, random_state=rng)
y = sparse.random((40, 40), density=0.01, random_state=rng)

x @ y # Numba compilation
@pytest.mark.parametrize("f", [operator.add, operator.mul])
def test_elemwise(benchmark, f, elemwise_args):
x, y = elemwise_args
f(x, y)

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