Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
53 changes: 53 additions & 0 deletions benchmarks/test_lheh5_io_bench.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""Benchmarks for LHEH5 I/O through the public pylhe API.

Source events are materialized before write timing. Reads are also fully
materialized so that the benchmark includes parsing into pylhe objects.
"""

from pathlib import Path

import pytest
import skhep_testdata

import pylhe


@pytest.fixture(scope="module")
def lhe_file():
source = skhep_testdata.data_path("pylhe-testfile-sherpa.hdf5")
return pylhe.LHEFile.fromfile(source, generator=False)


FORMATS = [
pytest.param(pylhe.HDF5_FORMAT, id="uncompressed-chunks"),
pytest.param(pylhe.HDF5_GZ_FORMAT, id="gzip-chunks"),
]


def _write_lhe(path: Path, lhe, lheformat) -> None:
lhe.tofile(path, lheformat=lheformat)


def _read_lhe(path: Path):
return pylhe.LHEFile.fromfile(path, generator=False)


@pytest.mark.parametrize("lheformat", FORMATS)
def test_lheh5_write_benchmark(benchmark, tmp_path, lhe_file, lheformat):
"""Measure writing already-materialized pylhe events."""
path = tmp_path / "write.hdf5"
benchmark(_write_lhe, path, lhe_file, lheformat)

assert path.stat().st_size > 0


@pytest.mark.parametrize("lheformat", FORMATS)
def test_lheh5_read_benchmark(benchmark, tmp_path, lhe_file, lheformat):
"""Measure reading and parsing a complete LHEH5 file."""
path = tmp_path / "read.hdf5"
_write_lhe(path, lhe_file, lheformat)

result = benchmark(_read_lhe, path)

assert isinstance(result.events, list)
assert len(result.events) == len(lhe_file.events)
Binary file added docs/source/_static/img/relative-performance.png
Comment thread
eduardo-rodrigues marked this conversation as resolved.
Resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions docs/source/comparison.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Comparison
==========

Performance
-----------

The results were produced with the
:download:`benchmark script <examples/benchmark_io_formats.py>`.


.. figure:: _static/img/relative-performance.png
:alt: LHEH5 read and write performance
:align: center
:width: 90%

Read and write performance for chunked compressed and uncompressed LHEH5 files. Overall is the geometric mean of relative read, write and storage performance.
Loading
Loading