From bcb75b453e99d82fd7eae94270bed23e5da01768 Mon Sep 17 00:00:00 2001 From: Sandro Campos Date: Mon, 9 Oct 2023 11:24:48 -0400 Subject: [PATCH] Try fixing the imports again --- benchmarks/benchmarks.py | 41 ++++++++++++++----- src/benchmarking_asv/example_benchmarks.py | 14 ------- tests/benchmarking_asv/conftest.py | 0 tests/benchmarking_asv/test_example_module.py | 6 +-- 4 files changed, 34 insertions(+), 27 deletions(-) delete mode 100644 src/benchmarking_asv/example_benchmarks.py delete mode 100644 tests/benchmarking_asv/conftest.py diff --git a/benchmarks/benchmarks.py b/benchmarks/benchmarks.py index ca3ef32..da2f974 100644 --- a/benchmarks/benchmarks.py +++ b/benchmarks/benchmarks.py @@ -1,16 +1,37 @@ -"""Two sample benchmarks to compute runtime and memory usage. +import benchmarking_asv as bench -For more information on writing benchmarks: -https://asv.readthedocs.io/en/stable/writing_benchmarks.html.""" -import example_benchmarks +class TimeSuite: # pylint: disable=too-few-public-methods + """An example benchmark that times the performance of various kinds + of iterating over dictionaries in Python.""" + def __init__(self): + self.d = {} -def time_computation(): - """Time computations are prefixed with 'time'.""" - example_benchmarks.runtime_computation() + def setup(self): + self.d = {} + for x in range(500): + self.d[x] = None + def time_keys(self): + """Time first method.""" + bench.example_module.run_time_computation() -def mem_list(): - """Memory computations are prefixed with 'mem' or 'peakmem'.""" - return example_benchmarks.memory_computation() + def time_iterkeys(self): + """Time second method.""" + bench.example_module.run_time_computation() + + def time_range(self): + """Time third method.""" + bench.example_module.run_time_computation() + + def time_xrange(self): + """Time fourth method.""" + bench.example_module.run_time_computation() + + +class MemSuite: # pylint: disable=too-few-public-methods + """An example benchmark that times memory consumption.""" + + def mem_list(self): + return bench.example_module.run_mem_computation() diff --git a/src/benchmarking_asv/example_benchmarks.py b/src/benchmarking_asv/example_benchmarks.py deleted file mode 100644 index 5a77b06..0000000 --- a/src/benchmarking_asv/example_benchmarks.py +++ /dev/null @@ -1,14 +0,0 @@ -"""An example module containing simplistic methods under benchmarking.""" - -import random -import time - - -def runtime_computation(): - """Runtime computation consuming between 0 and 5 seconds.""" - time.sleep(random.uniform(0, 5)) - - -def memory_computation(): - """Memory computation for a random list up to 512 samples.""" - return [0] * random.randint(0, 512) diff --git a/tests/benchmarking_asv/conftest.py b/tests/benchmarking_asv/conftest.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/benchmarking_asv/test_example_module.py b/tests/benchmarking_asv/test_example_module.py index 3ff9ebb..96acc2f 100644 --- a/tests/benchmarking_asv/test_example_module.py +++ b/tests/benchmarking_asv/test_example_module.py @@ -1,15 +1,15 @@ """An example module containing testing of mock functions.""" -import benchmarking_asv +from benchmarking_asv import example_module def test_greetings() -> None: """Verify the output of the `greetings` function""" - output = benchmarking_asv.example_module.greetings() + output = example_module.greetings() assert output == "Hello from LINCC-Frameworks!" def test_meaning() -> None: """Verify the output of the `meaning` function""" - output = benchmarking_asv.example_module.meaning() + output = example_module.meaning() assert output == 42