Batch 4: Modernize Python scripts (checkcpu.py and timer.py)#10
Merged
Conversation
checkcpu.py: - Python 3 with type hints - Cross-platform support: Linux and macOS - Comprehensive CPU information: - Logical and physical CPU count - CPU model and vendor - CPU frequency (MHz) - Cache sizes (L1, L2, L3) - CPU flags/features - Virtual CPU detection (hypervisor) - Platform and architecture - Optional CPU usage percentage (psutil or /proc/stat fallback) - Optional CPU temperature (psutil sensors) - JSON output format - Verbose mode to show all CPU flags - Argument parsing with argparse - Platform-specific info extraction (Linux /proc/cpuinfo, macOS sysctl) timer.py: - Python 3 with type hints - Command benchmarking tool with statistics - Multiple iteration support with statistics: - Minimum, maximum, mean, median time - Standard deviation - Total time - Success/failure tracking - Warmup runs (excluded from statistics) - Command timeout support - Compare mode for benchmarking multiple commands - Multiple output formats: text, JSON, CSV - Human-readable time formatting (μs, ms, s, m:s) - Verbose progress indication - Error handling and exit codes
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Modernized Python scripts to Python 3 with comprehensive features:
Changes
checkcpu.py
timer.py
Migration Notes
checkcpu.py:
python checkcpu.py(Python 2, just printed CPU count)python3 checkcpu.py(detailed info)python3 checkcpu.py --jsontimer.py:
python timer.py(Python 2, hardcoded loop counter)python3 timer.py "command"(benchmark any command)Testing
Both scripts tested for:
Examples
checkcpu.py:
timer.py:
Dependencies
Both scripts use only Python standard library except for optional features:
Optional (graceful fallback if not installed):
Install with:
pip3 install psutil