You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/TESTING.md
+123Lines changed: 123 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -72,6 +72,129 @@ go test -race ./...
72
72
### Performance / Timing
73
73
-**`submit_timing_test.go`** - Measures latency from `handleBlockShare` entry to `submitblock` invocation
74
74
- Benchmark suites live alongside the code as `*_bench_test.go` files; run them with `go test -run '^$' -bench . -benchmem ./...`.
75
+
-**`miner_decode_bench_test.go`** - Stratum decode microbenchmarks comparing full JSON unmarshal vs fast/manual sniffing for `ping`, `subscribe`, `authorize`, and `submit`.
76
+
-**`stratum_fastpath_bench_test.go`** - Stratum encode microbenchmarks comparing normal vs fast-path response encoding (`true`, `pong`, subscribe response in CKPool and expanded modes).
77
+
78
+
### Stratum Fast-Path Benchmarks
79
+
80
+
Use these commands to compare normal vs fast decode/encode paths without running unit tests:
81
+
82
+
```bash
83
+
# Decode comparison (full JSON unmarshal vs fast/manual sniff path)
84
+
go test -run '^$' -bench 'BenchmarkStratumDecode(FastJSON|Manual)' -benchmem .
85
+
86
+
# Encode comparison (normal vs fast response encoding)
87
+
go test -run '^$' -bench 'BenchmarkStratumEncode' -benchmem .
88
+
89
+
# Run both together
90
+
go test -run '^$' -bench 'BenchmarkStratum(Decode(FastJSON|Manual)|Encode)' -benchmem .
91
+
```
92
+
93
+
For more stable comparisons across changes/machines, run multiple samples and (optionally) compare with `benchstat`:
94
+
95
+
```bash
96
+
# Baseline / candidate example
97
+
go test -run '^$' -bench 'BenchmarkStratum(Decode(FastJSON|Manual)|Encode)' -benchmem -count=5 .> before.txt
98
+
go test -run '^$' -bench 'BenchmarkStratum(Decode(FastJSON|Manual)|Encode)' -benchmem -count=5 .> after.txt
- Normal encode: `157.6 ns/op`, `204 B/op`, `4 allocs/op`
131
+
- Fast encode: `48.34 ns/op`, `0 B/op`, `0 allocs/op`
132
+
- Roughly **3.3x faster**
133
+
-**Encode (`pong` response)**
134
+
- Normal encode: `168.9 ns/op`, `205 B/op`, `4 allocs/op`
135
+
- Fast encode: `45.13 ns/op`, `0 B/op`, `0 allocs/op`
136
+
- Roughly **3.7x faster**
137
+
-**Encode (`mining.subscribe`, CKPool mode)**
138
+
- Normal encode: `346.7 ns/op`, `501 B/op`, `11 allocs/op`
139
+
- Fast encode: `62.73 ns/op`, `0 B/op`, `0 allocs/op`
140
+
- Roughly **5.5x faster**
141
+
-**Encode (`mining.subscribe`, expanded mode)**
142
+
- Normal encode: `630.7 ns/op`, `1063 B/op`, `17 allocs/op`
143
+
- Fast encode: `105.9 ns/op`, `0 B/op`, `0 allocs/op`
144
+
- Roughly **6.0x faster**
145
+
146
+
Notes:
147
+
148
+
- These are **microbenchmarks** of parsing/encoding paths, not full end-to-end pool throughput benchmarks.
149
+
- Re-run on your target hardware and compare with `benchstat` before using the numbers for capacity planning.
150
+
151
+
### Hex Fast-Path Benchmarks
152
+
153
+
Hex encode/decode microbenchmarks live in `job_utils_hex_bench_test.go` and compare LUT-based helpers vs stdlib (`encoding/hex`) and alternate implementations.
154
+
155
+
Example focused command (decode + encode + uint32 hex parse):
156
+
157
+
```bash
158
+
go test -run '^$' -bench 'Benchmark(DecodeHexToFixedBytesBytes_(32_(PoolPairLUT|Std)|4_(PoolPairLUT|Std))|ParseUint32BEHexBytes_(LUT|Switch)|Encode(BytesToFixedHex_32_Std|32ToHex64Lower_(Unrolled|2ByteLUTLoop|LUTLoop)|ToString_32_(Std|StdStackBuf|Unrolled)))' -benchmem -benchtime=100ms .
0 commit comments