Skip to content

Commit 1a88cfa

Browse files
committed
[KLC-2387] extract MB/s metric row format to a constant
Sonar flagged the printf template " %-32s %7.1f MB/s %s (pass≥%.0f, fail<%.0f MB/s)\n" as duplicated 5 times across printNetworkSection and printCryptoSection. Centralised as metricThroughputMBpsRowFmt so future column-width or label-format changes stay consistent across sections.
1 parent 2a056dc commit 1a88cfa

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

cmd/benchmark/report.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,11 @@ func PrintReport(results *BenchmarkResults, format string) {
345345

346346
const reportWidth = 70
347347

348+
// metricThroughputMBpsRowFmt is the printf template for MB/s metric rows
349+
// (network throughput + every crypto MB/s metric). Centralised so column
350+
// width and pass/fail label format stay consistent across sections.
351+
const metricThroughputMBpsRowFmt = " %-32s %7.1f MB/s %s (pass≥%.0f, fail<%.0f MB/s)\n"
352+
348353
func printText(results *BenchmarkResults) {
349354
sep := strings.Repeat("─", reportWidth)
350355
si := results.SystemInfo
@@ -479,7 +484,7 @@ func printNetworkSection(r *NetworkResult, v verdict, sep string) {
479484
"Latency P50:", p50us, p50v.Icon(), netLatP50PassUs, netLatP50FailUs)
480485
fmt.Printf(" %-32s %8.1f µs %s (pass<%.0f, fail≥%.0f µs)\n",
481486
"Latency P99:", p99us, p99v.Icon(), netLatP99PassUs, netLatP99FailUs)
482-
fmt.Printf(" %-32s %7.1f MB/s %s (pass≥%.0f, fail<%.0f MB/s)\n",
487+
fmt.Printf(metricThroughputMBpsRowFmt,
483488
"Throughput:", r.ThroughputMBps, thrV.Icon(), netThroughputPassMBps, netThroughputFailMBps)
484489

485490
fmt.Println()
@@ -575,16 +580,16 @@ func printCryptoSection(r *CryptoResult, v verdict, sep string) {
575580
kV := metricVerdict(r.Keccak256MBps, cryptoKeccak256PassMBps, cryptoKeccak256FailMBps)
576581
edV := metricVerdict(r.Ed25519VerifyOpsPerSec, cryptoEd25519VerifyPassOps, cryptoEd25519VerifyFailOps)
577582

578-
fmt.Printf(" %-32s %7.1f MB/s %s (pass≥%.0f, fail<%.0f MB/s)\n",
583+
fmt.Printf(metricThroughputMBpsRowFmt,
579584
"SHA-256 (1 KiB blocks):", r.SHA256MBps, s256V.Icon(),
580585
cryptoSHA256SmallPassMBps, cryptoSHA256SmallFailMBps)
581-
fmt.Printf(" %-32s %7.1f MB/s %s (pass≥%.0f, fail<%.0f MB/s)\n",
586+
fmt.Printf(metricThroughputMBpsRowFmt,
582587
"SHA-256 (16 KiB blocks):", r.SHA256LargeMBps, s256LV.Icon(),
583588
cryptoSHA256LargePassMBps, cryptoSHA256LargeFailMBps)
584-
fmt.Printf(" %-32s %7.1f MB/s %s (pass≥%.0f, fail<%.0f MB/s)\n",
589+
fmt.Printf(metricThroughputMBpsRowFmt,
585590
"Blake2b-512 (16 KiB):", r.Blake2bMBps, b2V.Icon(),
586591
cryptoBlake2bPassMBps, cryptoBlake2bFailMBps)
587-
fmt.Printf(" %-32s %7.1f MB/s %s (pass≥%.0f, fail<%.0f MB/s)\n",
592+
fmt.Printf(metricThroughputMBpsRowFmt,
588593
"Keccak-256 (16 KiB):", r.Keccak256MBps, kV.Icon(),
589594
cryptoKeccak256PassMBps, cryptoKeccak256FailMBps)
590595
fmt.Printf(" %-32s %s %s (pass≥%.0fK, fail<%.0fK ops/s)\n",

0 commit comments

Comments
 (0)