<!-- DO NOT EDIT. -->
<!-- THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. -->
<!-- TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: -->
<!-- "auto_examples/readers_writers/plot_performance_caching.py" -->
<!-- LINE NUMBERS ARE GIVEN BELOW. -->

#### NOTE
[Go to the end](#sphx-glr-download-auto-examples-readers-writers-plot-performance-caching-py)
to download the full example code.

<a id="sphx-glr-auto-examples-readers-writers-plot-performance-caching-py"></a>

# Performance and Caching

All readers support automatic caching for improved performance.

<!-- GENERATED FROM PYTHON SOURCE LINES 8-34 -->
```Python
import os
from pathlib import Path
import time

import matplotlib.pyplot as plt

from pylimer_tools.io.extract_thermo_data import extract_thermo_params


# Read complete log file
def _find_fixtures_dir() -> Path:
    for cur in (
        [Path(__file__).resolve().parent] if "__file__" in globals() else []
    ) + [Path.cwd()]:
        for p in [cur] + list(cur.parents):
            candidate = p / "tests" / "pylimer_tools" / "fixtures"
            if candidate.is_dir():
                return candidate
    return Path("tests/pylimer_tools/fixtures").resolve()


_fixtures_dir = _find_fixtures_dir()
log_file = str(_fixtures_dir / "log.lammps")

time_start = time.time()
```

<!-- GENERATED FROM PYTHON SOURCE LINES 35-37 -->

[`extract_thermo_params()`](../../pylimer_tools.io.html.md#pylimer_tools.io.extract_thermo_data.extract_thermo_params) is a more elaborate version of
[`read_log_file()`](../../pylimer_tools.io.html.md#pylimer_tools.io.read_lammps_output_file.read_log_file)

<!-- GENERATED FROM PYTHON SOURCE LINES 37-52 -->
```Python
thermo_data = extract_thermo_params(log_file, use_cache=False)
time_end = time.time()

time_no_cache = time_end - time_start

time_start = time.time()
thermo_data = extract_thermo_params(log_file, use_cache=True)
time_end = time.time()

time_cache = time_end - time_start

plt.figure()
plt.bar(["Without Cache", "With Cache"], [time_no_cache, time_cache])
plt.ylabel("Time [s]")
plt.show()
```

**Total running time of the script:** (0 minutes 0.028 seconds)

<a id="sphx-glr-download-auto-examples-readers-writers-plot-performance-caching-py"></a>

[`Download Jupyter notebook: plot_performance_caching.ipynb`](_downloads/769a5fd3e1ade99dbc7d472abe413793/plot_performance_caching.ipynb)

[`Download Python source code: plot_performance_caching.py`](_downloads/335e2f233301388c14067f361380323f/plot_performance_caching.py)

[`Download zipped: plot_performance_caching.zip`](_downloads/5b7c15dedfb08f974d474562e1c1d833/plot_performance_caching.zip)

[Gallery generated by Sphinx-Gallery](https://sphinx-gallery.github.io)
