Skip to content

Commit

Permalink
Convert the benchmarks into a package so that we can use relative imp…
Browse files Browse the repository at this point in the history
…orts.
  • Loading branch information
vyasr committed Jun 23, 2022
1 parent 1025be4 commit 5db4589
Show file tree
Hide file tree
Showing 17 changed files with 37 additions and 52 deletions.
1 change: 1 addition & 0 deletions python/cudf/benchmarks/API/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2022, NVIDIA CORPORATION.
5 changes: 3 additions & 2 deletions python/cudf/benchmarks/API/bench_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

import numpy
import pytest
from config import cudf, cupy
from utils import accepts_cudf_fixture

from ..common.config import cudf, cupy
from ..common.utils import accepts_cudf_fixture


@pytest.mark.parametrize("N", [100, 1_000_000])
Expand Down
3 changes: 2 additions & 1 deletion python/cudf/benchmarks/API/bench_frame_or_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

import numpy as np
import pytest
from utils import accepts_cudf_fixture, make_gather_map

from ..common.utils import accepts_cudf_fixture, make_gather_map


@accepts_cudf_fixture(cls="frame_or_index", dtype="int")
Expand Down
3 changes: 2 additions & 1 deletion python/cudf/benchmarks/API/bench_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import pytest
import pytest_cases
from config import cudf, cupy

from ..common.config import cudf, cupy


@pytest_cases.parametrize_with_cases("objs", prefix="concat")
Expand Down
3 changes: 2 additions & 1 deletion python/cudf/benchmarks/API/bench_functions_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"""Test cases for benchmarks in bench_functions.py."""

import pytest_cases
from config import NUM_ROWS, cudf, cupy

from ..common.config import NUM_ROWS, cudf, cupy


@pytest_cases.parametrize("nr", NUM_ROWS)
Expand Down
5 changes: 3 additions & 2 deletions python/cudf/benchmarks/API/bench_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"""Benchmarks of Index methods."""

import pytest
from config import cudf, cupy
from utils import accepts_cudf_fixture

from ..common.config import cudf, cupy
from ..common.utils import accepts_cudf_fixture


@pytest.mark.parametrize("N", [100, 1_000_000])
Expand Down
3 changes: 2 additions & 1 deletion python/cudf/benchmarks/API/bench_indexed_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"""Benchmarks of IndexedFrame methods."""

import pytest
from utils import accepts_cudf_fixture

from ..common.utils import accepts_cudf_fixture


@accepts_cudf_fixture(cls="indexedframe", dtype="int")
Expand Down
3 changes: 2 additions & 1 deletion python/cudf/benchmarks/API/bench_multiindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import numpy as np
import pandas as pd
import pytest
from config import cudf

from ..common.config import cudf


@pytest.fixture
Expand Down
5 changes: 3 additions & 2 deletions python/cudf/benchmarks/API/bench_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"""Benchmarks of Series methods."""

import pytest
from config import cudf, cupy
from utils import accepts_cudf_fixture

from ..common.config import cudf, cupy
from ..common.utils import accepts_cudf_fixture


@pytest.mark.parametrize("N", [100, 1_000_000])
Expand Down
1 change: 1 addition & 0 deletions python/cudf/benchmarks/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2022, NVIDIA CORPORATION.
12 changes: 0 additions & 12 deletions python/cudf/benchmarks/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
appropriately.
"""
import os
import sys

# Environment variable-based configuration of benchmarking pandas or cudf.
collect_ignore = []
Expand Down Expand Up @@ -49,17 +48,6 @@ def pytest_collection_modifyitems(session, config, items):
pass


def pytest_sessionstart(session):
"""Add the common files to the path for all tests to import."""
sys.path.insert(0, os.path.join(os.getcwd(), "common"))


def pytest_sessionfinish(session, exitstatus):
"""Clean up sys.path after exit."""
if "common" in sys.path[0]:
del sys.path[0]


# Constants used to define benchmarking standards.
if "CUDF_BENCHMARKS_DEBUG_ONLY" in os.environ:
NUM_ROWS = [10, 20]
Expand Down
3 changes: 2 additions & 1 deletion python/cudf/benchmarks/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from numbers import Real

import pytest_cases
from config import NUM_COLS, NUM_ROWS, cudf, cupy

from .config import NUM_COLS, NUM_ROWS, cudf, cupy


def make_gather_map(len_gather_map: Real, len_column: Real, how: str):
Expand Down
32 changes: 8 additions & 24 deletions python/cudf/benchmarks/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,39 +44,23 @@
As a result, it is provided as a separate fixture.
"""

import os
import string
import sys

import pytest_cases

# TODO: Rather than doing this path hacking (including the sessionstart and
# sessionfinish hooks), we could just make the benchmarks a (sub)package to
# enable relative imports. A minor change to consider when these are ported
# into the main repo.
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "common"))

from config import cudf # noqa: W0611, E402, F401
from utils import ( # noqa: E402
OrderedSet,
collapse_fixtures,
column_generators,
make_fixture,
)

# Turn off isort until we upgrade to 5.8.0
# https://github.com/pycqa/isort/issues/1594
# isort: off
from config import ( # noqa: W0611, E402, F401
from .common.config import ( # noqa: W0611, F401
NUM_COLS,
NUM_ROWS,
collect_ignore,
cudf,
pytest_collection_modifyitems,
pytest_sessionfinish,
pytest_sessionstart,
)

# isort: on
from .common.utils import (
OrderedSet,
collapse_fixtures,
column_generators,
make_fixture,
)


@pytest_cases.fixture(params=[0, 1], ids=["AxisIndex", "AxisColumn"])
Expand Down
1 change: 1 addition & 0 deletions python/cudf/benchmarks/internal/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) 2022, NVIDIA CORPORATION.
3 changes: 2 additions & 1 deletion python/cudf/benchmarks/internal/bench_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import pytest
import pytest_cases
from utils import (

from ..common.utils import (
accepts_cudf_fixture,
make_boolean_mask_column,
make_gather_map,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

"""Benchmarks of internal DataFrame methods."""

from utils import accepts_cudf_fixture, make_boolean_mask_column
from ..common.utils import accepts_cudf_fixture, make_boolean_mask_column


@accepts_cudf_fixture(cls="dataframe", dtype="int")
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/benchmarks/internal/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

"""Defines pytest fixtures for internal benchmarks."""

from config import NUM_ROWS, cudf
from utils import (
from ..common.config import NUM_ROWS, cudf
from ..common.utils import (
OrderedSet,
collapse_fixtures,
column_generators,
Expand Down

0 comments on commit 5db4589

Please sign in to comment.