Source file src/crypto/internal/edwards25519/field/fe_bench_test.go

     1  // Copyright (c) 2019 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  
     5  package field
     6  
     7  import "testing"
     8  
     9  func BenchmarkAdd(b *testing.B) {
    10  	x := new(Element).One()
    11  	y := new(Element).Add(x, x)
    12  	b.ResetTimer()
    13  	for i := 0; i < b.N; i++ {
    14  		x.Add(x, y)
    15  	}
    16  }
    17  
    18  func BenchmarkMultiply(b *testing.B) {
    19  	x := new(Element).One()
    20  	y := new(Element).Add(x, x)
    21  	b.ResetTimer()
    22  	for i := 0; i < b.N; i++ {
    23  		x.Multiply(x, y)
    24  	}
    25  }
    26  
    27  func BenchmarkSquare(b *testing.B) {
    28  	x := new(Element).Add(feOne, feOne)
    29  	b.ResetTimer()
    30  	for i := 0; i < b.N; i++ {
    31  		x.Square(x)
    32  	}
    33  }
    34  
    35  func BenchmarkInvert(b *testing.B) {
    36  	x := new(Element).Add(feOne, feOne)
    37  	b.ResetTimer()
    38  	for i := 0; i < b.N; i++ {
    39  		x.Invert(x)
    40  	}
    41  }
    42  
    43  func BenchmarkMult32(b *testing.B) {
    44  	x := new(Element).One()
    45  	b.ResetTimer()
    46  	for i := 0; i < b.N; i++ {
    47  		x.Mult32(x, 0xaa42aa42)
    48  	}
    49  }
    50  

View as plain text