• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2021 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package fiat_test
6
7import (
8	"crypto/internal/nistec/fiat"
9	"testing"
10)
11
12func BenchmarkMul(b *testing.B) {
13	b.Run("P224", func(b *testing.B) {
14		v := new(fiat.P224Element).One()
15		b.ReportAllocs()
16		b.ResetTimer()
17		for i := 0; i < b.N; i++ {
18			v.Mul(v, v)
19		}
20	})
21	b.Run("P384", func(b *testing.B) {
22		v := new(fiat.P384Element).One()
23		b.ReportAllocs()
24		b.ResetTimer()
25		for i := 0; i < b.N; i++ {
26			v.Mul(v, v)
27		}
28	})
29	b.Run("P521", func(b *testing.B) {
30		v := new(fiat.P521Element).One()
31		b.ReportAllocs()
32		b.ResetTimer()
33		for i := 0; i < b.N; i++ {
34			v.Mul(v, v)
35		}
36	})
37}
38
39func BenchmarkSquare(b *testing.B) {
40	b.Run("P224", func(b *testing.B) {
41		v := new(fiat.P224Element).One()
42		b.ReportAllocs()
43		b.ResetTimer()
44		for i := 0; i < b.N; i++ {
45			v.Square(v)
46		}
47	})
48	b.Run("P384", func(b *testing.B) {
49		v := new(fiat.P384Element).One()
50		b.ReportAllocs()
51		b.ResetTimer()
52		for i := 0; i < b.N; i++ {
53			v.Square(v)
54		}
55	})
56	b.Run("P521", func(b *testing.B) {
57		v := new(fiat.P521Element).One()
58		b.ReportAllocs()
59		b.ResetTimer()
60		for i := 0; i < b.N; i++ {
61			v.Square(v)
62		}
63	})
64}
65