Skip to content

feat: --benchmark mode (pure-Python hashrate baseline)#5

Merged
devAsmodeus merged 1 commit intomainfrom
feat/benchmark-mode
Apr 30, 2026
Merged

feat: --benchmark mode (pure-Python hashrate baseline)#5
devAsmodeus merged 1 commit intomainfrom
feat/benchmark-mode

Conversation

@devAsmodeus
Copy link
Copy Markdown
Owner

Summary

Adds hope-hash --benchmark for measuring the pure-Python SHA-256 baseline
before any C/Rust/SIMD/GPU optimizations (ROADMAP levels 2–3). Without a
"before" number, "after" numbers mean nothing.

What it does

  • Reuses the existing parallel.start_pool machinery so the measured code
    path is exactly the same as real mining (including mid-state SHA-256
    from v0.3.0).
  • Synthetic header (same shape as real block headers) + target=0 so
    workers never find a hit and just keep hashing for the full duration.
  • Reports platform, Python build, CPU, total hashes, wall time, total H/s,
    per-worker H/s.
  • Returns BenchResult dataclass for programmatic use (future scaling
    benchmarks, JSON exports).

Sample run

Intel i7-12700H, 4 workers, 5 seconds:

[bench] platform: Windows-10-10.0.26200-SP0
[bench] python:   3.11.9 (cpython)
[bench] cpu:      16 logical cores
[bench]   t=  1.0s  hashes=     2,654,208  rate=2.64 MH/s
[bench]   t=  3.0s  hashes=     9,093,120  rate=3.01 MH/s
[bench] === result ===
[bench]   total hashes:   11,436,032
[bench]   wall time:           5.01s
[bench]   hashrate:        2.28 MH/s
[bench]   per-worker:    570.23 KH/s (workers: 4)

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:

  • C-extension via ctypes/cffi: marginal gain over hashlib (which already
    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.
  • Rust via PyO3: the right next step (the sha2 crate has SIMD baked
    in), 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 locally
  • hope-hash --benchmark --bench-duration 5 --workers 4 runs cleanly
    and reports MH/s
  • hope-hash --benchmark --demo rejected with explicit error
  • CI matrix Python 3.11/3.12/3.13 × ubuntu/windows/macos

Related

Sets up the baseline measurement requested by ROADMAP "Идеи поверх скелета /
Бенчмарк-режим" and unblocks the C/Rust/SIMD discussion in levels 2–3.

🤖 Generated with Claude Code

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>
@devAsmodeus devAsmodeus merged commit 2ca447a into main Apr 30, 2026
10 checks passed
@devAsmodeus devAsmodeus deleted the feat/benchmark-mode branch April 30, 2026 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant