Skip to content

Commit

Permalink
secp256k1: Add scalar base mult variant benchmarks.
Browse files Browse the repository at this point in the history
ScalarBaseMultNonConstFast   64886   18242 ns/op    0 B/op   0 allocs/op
ScalarBaseMultNonConstSlow   13261   91696 ns/op   64 B/op   2 allocs/op
  • Loading branch information
davecgh committed Mar 19, 2024
1 parent 2ee2ebe commit 25adf60
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion dcrec/secp256k1/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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) {
Expand Down

0 comments on commit 25adf60

Please sign in to comment.