From 272369feb38373af3ce5040df5909dd99284f744 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Tue, 19 Mar 2024 11:05:23 -0500 Subject: [PATCH] secp256k1: Add scalar base mult variant benchmarks. ScalarBaseMultNonConstFast 64886 18242 ns/op 0 B/op 0 allocs/op ScalarBaseMultNonConstSlow 13261 91696 ns/op 64 B/op 2 allocs/op --- dcrec/secp256k1/bench_test.go | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/dcrec/secp256k1/bench_test.go b/dcrec/secp256k1/bench_test.go index 2b2681856a..813d5070e4 100644 --- a/dcrec/secp256k1/bench_test.go +++ b/dcrec/secp256k1/bench_test.go @@ -53,7 +53,7 @@ func BenchmarkAddNonConstNotZOne(b *testing.B) { } // BenchmarkScalarBaseMultNonConst benchmarks multiplying a scalar by the base -// point of the curve. +// point of the curve using whichever variant is active. func BenchmarkScalarBaseMultNonConst(b *testing.B) { k := hexToModNScalar("d74bf844b0862475103d96a611cf2d898447e288d34b360bc885cb8ce7c00575") @@ -65,6 +65,32 @@ func BenchmarkScalarBaseMultNonConst(b *testing.B) { } } +// BenchmarkScalarBaseMultNonConstFast benchmarks multiplying a scalar by the +// base point of the curve using the fast variant. +func BenchmarkScalarBaseMultNonConstFast(b *testing.B) { + k := hexToModNScalar("d74bf844b0862475103d96a611cf2d898447e288d34b360bc885cb8ce7c00575") + + b.ReportAllocs() + b.ResetTimer() + var result JacobianPoint + for i := 0; i < b.N; i++ { + scalarBaseMultNonConstFast(k, &result) + } +} + +// BenchmarkScalarBaseMultNonConstSlow benchmarks multiplying a scalar by the +// base point of the curve using the resource-constrained slow variant. +func BenchmarkScalarBaseMultNonConstSlow(b *testing.B) { + k := hexToModNScalar("d74bf844b0862475103d96a611cf2d898447e288d34b360bc885cb8ce7c00575") + + b.ReportAllocs() + b.ResetTimer() + var result JacobianPoint + for i := 0; i < b.N; i++ { + scalarBaseMultNonConstSlow(k, &result) + } +} + // BenchmarkSplitK benchmarks decomposing scalars into a balanced length-two // representation. func BenchmarkSplitK(b *testing.B) {