pypindou.benchmark.runner

Small benchmark helpers for pattern-generation experiments.

Benchmarks in this module intentionally reuse the public pypindou.pattern.generate_pattern() API. They are useful for comparing image size, palette size, color limits, and quantization strategies without introducing a separate CLI.

Example:

>>> from pypindou.benchmark.runner import results_to_rows
>>> results_to_rows([])
[]

BenchmarkCase

class pypindou.benchmark.runner.BenchmarkCase(image, palette, width, height, max_colors=None, quantize='nearest')[源代码]

One benchmark case.

参数:
  • image (Union[str, pathlib.Path]) -- Source image path.

  • palette (str) -- Built-in palette id.

  • width (int) -- Target bead-grid width.

  • height (int) -- Target bead-grid height.

  • max_colors (Optional[int], optional) -- Optional maximum color count, defaults to None.

  • quantize (str, optional) -- Quantization method, defaults to "nearest".

BenchmarkResult

class pypindou.benchmark.runner.BenchmarkResult(image, palette, width, height, max_colors, quantize, bead_count, used_colors, mean_error, elapsed)[源代码]

One benchmark result row.

参数:
  • image (str) -- Source image path as text.

  • palette (str) -- Built-in palette id.

  • width (int) -- Target bead-grid width.

  • height (int) -- Target bead-grid height.

  • max_colors (Optional[int]) -- Optional maximum color count.

  • quantize (str) -- Quantization method.

  • bead_count (int) -- Number of active beads.

  • used_colors (int) -- Number of colors used by the generated pattern.

  • mean_error (float) -- Mean active-pixel quantization error.

  • elapsed (float) -- Average elapsed seconds.

run_benchmark

pypindou.benchmark.runner.run_benchmark(cases, *, repeat=1)[源代码]

Run pattern-generation benchmarks.

参数:
  • cases (Iterable[BenchmarkCase]) -- Benchmark cases to execute.

  • repeat (int, optional) -- Number of times to run each case, defaults to 1.

返回:

Benchmark results in input order.

返回类型:

List[BenchmarkResult]

抛出:

ValueError -- If repeat is not positive.

results_to_rows

pypindou.benchmark.runner.results_to_rows(results)[源代码]

Convert benchmark results to dictionaries.

参数:

results (Sequence[BenchmarkResult]) -- Benchmark result objects.

返回:

Shallow dictionary rows.

返回类型:

List[dict]