Skip to content

Conversation

@errnair
Copy link
Owner

@errnair errnair commented Nov 7, 2025

Summary

Modernized Python scripts to Python 3 with comprehensive features:

  • checkcpu.py - Enhanced CPU information tool
  • timer.py - Command benchmarking tool

Changes

checkcpu.py

  • Python 3 with type hints for better code quality
  • Cross-platform support:
    • Linux: Reads /proc/cpuinfo for detailed CPU info
    • macOS: Uses sysctl for CPU information
  • Comprehensive CPU information display:
    • Logical and physical CPU count
    • CPU model name and vendor ID
    • CPU frequency in MHz
    • Cache sizes (L1I, L1D, L2, L3)
    • CPU flags and features
    • Virtual CPU detection (detects KVM, QEMU, VMware, Xen, etc.)
    • Platform and architecture
  • Optional features:
    • CPU usage percentage (via psutil or /proc/stat fallback)
    • CPU temperature (via psutil sensors if available)
  • Output formats:
    • Human-readable text (default)
    • JSON for integration with monitoring tools
  • Verbose mode to display all CPU flags/features
  • Proper argument parsing with argparse
  • Graceful degradation when optional features unavailable

timer.py

  • Python 3 with type hints and modern best practices
  • Full-featured benchmarking tool for shell commands
  • Multiple iteration support with comprehensive statistics:
    • Minimum, maximum, mean, median execution time
    • Standard deviation for consistency analysis
    • Total execution time
    • Success/failure tracking
  • Warmup runs excluded from statistics (reduces variance)
  • Command timeout support to prevent hanging
  • Compare mode for benchmarking multiple commands side-by-side
  • Multiple output formats:
    • Human-readable text with formatted times
    • JSON for programmatic analysis
    • CSV for spreadsheet import
  • Human-readable time formatting:
    • Microseconds (μs) for very fast commands
    • Milliseconds (ms) for fast commands
    • Seconds (s) for normal commands
    • Minutes:seconds (m:s) for long-running commands
  • Verbose progress indication during execution
  • Comprehensive error handling with proper exit codes
  • Command execution via subprocess with stderr capture

Migration Notes

checkcpu.py:

  • Old: python checkcpu.py (Python 2, just printed CPU count)
  • New: python3 checkcpu.py (detailed info)
  • Breaking change: Output format changed from single number to formatted text
  • For scripts parsing output, use: python3 checkcpu.py --json

timer.py:

  • Old: python timer.py (Python 2, hardcoded loop counter)
  • New: python3 timer.py "command" (benchmark any command)
  • Breaking change: Requires command argument
  • Old script had no practical use, new one is a proper benchmarking tool

Testing

Both scripts tested for:

  • Python 3 syntax compilation
  • Functional testing on macOS
  • JSON output validation
  • Error handling
  • Cross-platform compatibility

Examples

checkcpu.py:

# Display CPU information python3 checkcpu.py # JSON output for monitoring integration python3 checkcpu.py --json # Show all CPU flags/features python3 checkcpu.py --verbose # JSON with all features python3 checkcpu.py --json --verbose

timer.py:

# Time a single command python3 timer.py "ls -la" # Run 10 iterations with statistics python3 timer.py -n 10 "curl https://example.com" # JSON output python3 timer.py --json "python script.py" # Compare two commands python3 timer.py --compare "grep pattern file" "rg pattern file" # Warmup runs + benchmark (reduces cache effects) python3 timer.py -n 100 --warmup 5 "echo test" # Export to CSV for analysis python3 timer.py --csv -n 50 "command" > results.csv # Verbose mode with progress python3 timer.py -v -n 10 "sleep 0.1" # Command timeout python3 timer.py --timeout 5 "long-running-command"

Dependencies

Both scripts use only Python standard library except for optional features:

Optional (graceful fallback if not installed):

  • psutil: For CPU usage percentage and temperature (checkcpu.py)

Install with: pip3 install psutil

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
@errnair errnair merged commit caf65a4 into master Nov 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants