Repository navigation
feat: speedup lheh5/hdf5 read performance #425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0f63c21
add hdf5 bench
APN-Pucky 5aa3949
read events in chunks to speedup
APN-Pucky c727825
speedup read, by storing get_particle comlumns
APN-Pucky 244e262
fix test
APN-Pucky f07d848
read once
APN-Pucky dae3648
add benchmark/comparison to docs
APN-Pucky cb2d31e
Merge branch 'main' into speedup_hdf5_read
APN-Pucky 8a884ea
Fix example paths in benchmark_io_formats.py documentation
APN-Pucky 0373db2
remove unused batch_size
APN-Pucky c4d9bad
Merge branch 'main' into speedup_hdf5_read
APN-Pucky ee5e7bb
Update src/pylhe/lheh5.py
APN-Pucky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.