feat: --benchmark mode (pure-Python hashrate baseline)#5
Merged
devAsmodeus merged 1 commit intomainfrom Apr 30, 2026
Merged
Conversation
Adds `hope-hash --benchmark [--bench-duration SEC]` for measuring the pure-Python SHA-256 baseline before C/Rust/SIMD/GPU optimizations (ROADMAP levels 2-3). Without a number "before", numbers "after" mean nothing. Mechanism: - Reuses existing parallel.start_pool/stop_pool machinery so the measured code path is exactly the same as real mining (incl. mid-state SHA-256 from v0.3.0) - Synthetic 76-byte header_base (same shape as real headers) + target=0 so workers never find a hit and just keep hashing - Periodic progress samples (~5 across the run), final aggregate Output includes platform, Python implementation, CPU info, total hashes, wall time, total H/s, per-worker H/s. Returns BenchResult dataclass for programmatic use. CLI: - --benchmark, --bench-duration SEC - Mutually exclusive with --demo (explicit error) - Reuses --workers for worker count Tests (3): - BenchResult.per_worker_hps math (incl. zero-workers safety) - 1-second smoke run in spawn subprocess: hashes > 0, hashrate > 0, duration close to requested Sample run (Intel i7-12700H, 4 workers, 5s): hashrate: 2.28 MH/s per-worker: 570 KH/s Bumps __version__ to 0.4.0. Tests: 98 -> 101. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
Adds
hope-hash --benchmarkfor measuring the pure-Python SHA-256 baselinebefore any C/Rust/SIMD/GPU optimizations (ROADMAP levels 2–3). Without a
"before" number, "after" numbers mean nothing.
What it does
parallel.start_poolmachinery so the measured codepath is exactly the same as real mining (including mid-state SHA-256
from v0.3.0).
target=0soworkers never find a hit and just keep hashing for the full duration.
per-worker H/s.
BenchResultdataclass for programmatic use (future scalingbenchmarks, JSON exports).
Sample run
Intel i7-12700H, 4 workers, 5 seconds:
This number (~570 KH/s/worker on a modern x86 core with hashlib) is the
target to beat with the next optimization step.
Why this approach
A few alternatives considered and rejected:
wraps OpenSSL/system libcrypto); the real Python overhead is between hashes
(struct.pack, copy, int comparison), not in the hash itself. Skip until we
rewrite the whole inner loop in C.
sha2crate has SIMD bakedin), but breaks the pure-stdlib invariant — needs an explicit decision
before we go there. This PR keeps that decision separate.
Test plan
py -3.11 -m unittest discover -s tests -v— 101/101 pass locallyhope-hash --benchmark --bench-duration 5 --workers 4runs cleanlyand reports MH/s
hope-hash --benchmark --demorejected with explicit errorRelated
Sets up the baseline measurement requested by ROADMAP "Идеи поверх скелета /
Бенчмарк-режим" and unblocks the C/Rust/SIMD discussion in levels 2–3.
🤖 Generated with Claude Code