A Python sandbox environment designed to benchmark and compare the performance and physical energy consumption of different sorting algorithms.
In earlier versions, CPU energy tracking was calculated using an unreliable 1-second threading poll that outputted an abstract score. Furthermore, algorithms were forced to load the dataset from the disk during their benchmark runs. This meant I was measuring disk I/O latency instead of the actual efficiency of the mathematical sorting logic.
This updated version was heavily refactored to focus on hardware truth:
- Physics over Abstract Scores: The main engine now dynamically profiles your host PC (identifying the CPU architecture), estimates the maximum TDP in Watts, and outputs actual energy costs in Joules, based strictly on core utilization and synchronous execution time.
- Pure Isolation: Arrays are loaded and copied in RAM before the timers run. Zero disk I/O bottleneck overheads.
- Extensible Plugin System: You no longer need to edit the engine logic to add a new sorting function. Anything placed in the
sorters/directory is automatically imported and tested.
Ensure you have Python 3 installed, then install the required tracking libraries:
pip install numpy matplotlib psutilTo start the testing pipeline, execute the main file:
python energy_counter.pyIf you don't have the dataset generated yet, the script will automatically create a testing package (random_words_array.npy) containing 1,000,000 random words to use as the baseline.
The system is entirely decoupled. To add your own algorithm, just drop a Python file into the sorters/ directory following a simple contract.
Example sorters/your_algorithm.py:
NAME = "My Custom Sort"
def sort(arr):
# Perform your sorting logic
return arrThe next time you start the benchmark, the script will passively discover your file, run it, and place it on the final grid alongside the default ones.
When the benchmark completes, a grid-based darkmode dashboard will render the results side-by-side, specifically focused on:
- Execution Time (Seconds)
- Active CPU Cores Utilized
- Memory Consumption (MB)
- Physical Energy Cost (Joules)
This project is licensed under the MIT License - see the LICENSE file for details. Built originally with the help of @Bita05.