This directory contains the results of benchmarking tests performed on the ChessMoveHeatmap project to evaluate the performance impact of Cython compilation under different configurations. The tests aim to identify the fastest and most efficient setup for running the project's unit tests and focus benchmarks.
The benchmarking was conducted under the following four scenarios, each involving targeted compilation of specific files:
-
Everything Compiled:
- All specified
.pyfiles in the repository and thepython-chesslibrary were compiled with Cython. - From the
python-chesslibrary:- Every
.pyfile in the library's directory, except for_interactive.py, was compiled.
- Every
- From the repository:
- The following files were compiled:
heatmaps\\__init__.pychmutils\\__init__.pychmengine\\utils\\pick.pychmengine\\utils\\__init__.pychmengine\\engines\\cmhmey1.pychmengine\\engines\\quartney.pychmengine\\engines\\cmhmey2.pychmengine\\engines\\__init__.pychmengine\\__init__.py
- The following files were compiled:
- All specified
-
Chess-lib Compiled:
- Only the targeted
.pyfiles in thepython-chesslibrary were compiled, excluding_interactive.py.
- Only the targeted
-
Repo Compiled:
- Only the targeted
.pyfiles in the repository (listed above) were compiled.
- Only the targeted
-
No Compilation:
- No Cython compilation was performed; all
.pyfiles ran as standard Python code.
- No Cython compilation was performed; all
- TestResults: Cython Both Fresh Setup Final
- TestResults: Cython Both Fresh Setup
- TestResults: Cython Both
- TestResults: Cython Main Only Fresh Setup
- TestResults: Cython Main Only
- TestResults: Cython PyChess Only Fresh Setup
- TestResults: Cython PyChess Only
- TestResults: No Cython Fresh No Setup
- TestResults: No Cython
- Setup Time: Total time taken to compile the specified
.pyfiles in the given scenario. - Full Test Suite Runtime: Total execution time for all 91 unit tests in the
testsdirectory. - Focus Test Runtime (
test_pick_move): Total runtime for thetest_pick_movefunction. s/branch: Time taken per first-level game tree branch analyzed by thepick_movemethod.- 90th Percentile Time (
s/branch): Time under which 90% ofs/branchmeasurements fall, representing upper-normal performance.
The s/branch metric represents the time taken by the pick_move method for each first-level game tree branch from the current board position. Here's a breakdown:
-
Notation:
srefers to the elapsed time in seconds.branchrefers to the number of first-level game tree branches analyzed.
-
Game Tree Exploration:
- The
pick_movemethod evaluates potential moves from a given position, exploring deeper branches in case of checks or captures. - The
s/branchmetric does not account for deeper game tree branches beyond the first level due to limitations in the unittest's scope.
- The
-
Example:
- For the initial chess position (
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1), the following applies:- White has 20 possible moves (first-level branches).
- Black's follow-up results in 20x20 = 400 boards analyzed.
- Since there are no checks or captures in this simplified example, the
pick_movemethod exits after analyzing the first two plies. - The reported
s/branchtime for this position is equivalent tos/20.
- For the initial chess position (
| Scenario | Setup Time | Full Test Suite Runtime | Focus Test Runtime (test_pick_move) |
Mean Pick Time (s/branch) |
90th Percentile Pick Time (s/branch) |
Mean Response Time (s/branch) |
90th Percentile Response Time (s/branch) |
Mean Revisit Time (s/branch) |
90th Percentile Revisit Time (s/branch) |
|---|---|---|---|---|---|---|---|---|---|
| Everything Compiled | 5 m 20 s | 11 m 49 s | 3 m 44 s | 0.0025 | 0.0027 | 0.02545 | 0.02656 | 0.0012 | 0.0013 |
| Chess-lib Compiled | 5 m 5 s | 12 m 20 s (+0:31) | 3 m 52 s (+0:08) | 0.00255 (+0.00005 s/branch) | 0.0028 (+0.00010 s/branch) | 0.0264 (+0.00095 s/branch) | 0.02762 (+0.00106 s/branch) | 0.00125 (+0.00005 s/branch) | 0.00135 (+0.00005 s/branch) |
| Repo Compiled | 16 s | 12 m 29 s (+0:40) | 3 m 52 s (+0:08) | 0.0026 (+0.00010 s/branch) | 0.00285 (+0.00015 s/branch) | 0.02635 (+0.00090 s/branch) | 0.02762 (+0.00106 s/branch) | 0.00125 (+0.00005 s/branch) | 0.00135 (+0.00005 s/branch) |
| No Compilation | 0 s | 12 m 50 s (+1:01) | 3 m 59 s (+0:15) | 0.0026 (+0.00010 s/branch) | 0.0029 (+0.00020 s/branch) | 0.02725 (+0.00180 s/branch) | 0.02868 (+0.00212 s/branch) | 0.00125 (+0.00005 s/branch) | 0.00135 (+0.00005 s/branch) |
The primary objective of this benchmarking experiment was to determine whether the speed gains from various compiled states justify their setup costs, particularly in the context of a continuous integration (CI) pipeline.
The results clearly show that the "Everything Compiled" setup offers the best overall performance, with significant runtime savings across all benchmarks. However, its high setup time of 5 minutes and 20 seconds makes it impractical for short-term or one-off executions, like those in a CI pipeline. On the other hand, the No Compilation setup, while slower in raw runtime, avoids any setup overhead and remains efficient for one-off tasks.
-
For Long-Term, Repeated Use:
- The "Everything Compiled" setup is the optimal choice for scenarios where the same code is run repeatedly over an extended period. The initial setup cost is easily amortized by the significant runtime savings across repeated executions.
-
For Short-Term, One-Off Use (e.g., CI Pipelines):
- The No Compilation setup is the best option for short-term or one-off tasks, such as CI pipeline actions, where minimizing total execution time (including setup) is critical.
These findings reinforce the importance of balancing setup costs against runtime savings when optimizing for different use cases, ensuring that the chosen setup is tailored to the specific needs of the task or workflow.
Follow these steps to reproduce the benchmarking tests:
-
Install Dependencies:
- Ensure you have Python 3.7 or higher and Cython installed in your environment.
-
Set Up a Virtual Environment (Highly Recommended):
- To avoid modifying your global Python environment, create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
- This ensures that any compilation or changes are restricted to the virtual environment.
- To avoid modifying your global Python environment, create and activate a virtual environment:
-
Compile the Code:
- Use the following commands to compile the code under different scenarios:
- Everything Compiled:
python setup.py --all - Chess-lib Compiled:
python setup.py --chess - Repo Compiled:
python setup.py --main
- Everything Compiled:
Important Note: The
setup.pyscript dynamically imports thechesslibrary to parse its module location in the active Python environment. If you do not use a virtual environment, your global site-packages version ofchessmay be compiled, which could have unintended consequences. - Use the following commands to compile the code under different scenarios:
-
Run the Tests:
- Execute the tests using the
pytestframework:pytest tests/
- Execute the tests using the
-
Focus Benchmark:
- Run the
test_pick_movebenchmark separately:pytest tests/test_pick_move.py
- Run the
The repository includes a dynamic GitHub Actions runner that executes only the tests relevant to the most recent code changes. This ensures efficient CI/CD pipelines without rerunning unnecessary tests. While the benchmarking tests were run manually for consistency and thoroughness, the dynamic runner complements ongoing development by keeping the testing process targeted and efficient.