Skip to content

Different results running benchmarks with and without the action #127

@andresliszt

Description

@andresliszt

Hello! Thanks for this amazing project. Maybe I'm too new on this, but I'm trying to configure the codspeed action, I'm getting different results in some scenarios. I'm working on a project which mixes python and rust through pyo3, and I have a test here, Which behaves completely different when I run it with and without the action.

import time

import pytest
import numpy as np
from scipy.spatial.distance import cdist  # type: ignore

from pymoors._pymoors import cross_euclidean_distances  # type: ignore


def test_cdist_pymoors(benchmark):
    matrix = np.random.rand(5000, 5000)
    result = benchmark(cross_euclidean_distances, matrix, matrix)
    assert result.shape == (5000, 5000)


def eculidean_distance_plus_time(matrix):
    start_time = time.perf_counter()
    result = cross_euclidean_distances(matrix, matrix)
    end_time = time.perf_counter()
    total = end_time - start_time
    return result, total


@pytest.mark.parametrize("n", [1000, 1500, 2000, 2500])
def test_compare_scipy_cdist_vs_pymoors(benchmark, n):
    matrix = np.random.rand(n, n)
    result_pymoors, total_time = benchmark(eculidean_distance_plus_time, matrix)
    # Measure the time for scipy's cdist using a timer
    start_time = time.perf_counter()
    result_scipy = cdist(matrix, matrix, metric="sqeuclidean")
    end_time = time.perf_counter()
    time_scipy = end_time - start_time
    # Check the result is the same
    np.testing.assert_allclose(result_pymoors, result_scipy, rtol=1e-5, atol=1e-8)
    # Check the time
    assert total_time < time_scipy

If I use the action the tests run like if I've deployed my package in debug mode, comparable with the time i got locally when i run them in debug mode

- name: Run benchmarks
  uses: CodSpeedHQ/action@v3
  with:
    token: ${{ secrets.CODSPEED_TOKEN }}
    run: |
      pytest -s -vvv tests/benchmarks --codspeed

But when I remove the action, and run the benchmark directly, the tests run just fine, like in release mode

- name: Run benchmarks
  run: pytest -s -vvv tests/benchmarks --codspeed

Is the action introducing a change in the runner machine? Is there a doc where I can see what is the action doing?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions