mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-14 12:06:40 +00:00
crypto: using testing.B.Loop (#32645)
before: go test -run=^$ -bench=. ./crypto/... 94.83s user 2.68s system 138% cpu 1:10.55 tota after: go test -run=^$ -bench=. ./crypto/... 75.43s user 2.58s system 123% cpu 1:03.01 total
This commit is contained in:
parent
e35c628656
commit
a499a11a16
6 changed files with 18 additions and 31 deletions
|
|
@ -303,8 +303,7 @@ func benchmarkSum(b *testing.B, size int, sse4, avx, avx2 bool) {
|
||||||
|
|
||||||
data := make([]byte, size)
|
data := make([]byte, size)
|
||||||
b.SetBytes(int64(size))
|
b.SetBytes(int64(size))
|
||||||
b.ResetTimer()
|
for b.Loop() {
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
Sum512(data)
|
Sum512(data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -319,8 +318,7 @@ func benchmarkWrite(b *testing.B, size int, sse4, avx, avx2 bool) {
|
||||||
data := make([]byte, size)
|
data := make([]byte, size)
|
||||||
h, _ := New512(nil)
|
h, _ := New512(nil)
|
||||||
b.SetBytes(int64(size))
|
b.SetBytes(int64(size))
|
||||||
b.ResetTimer()
|
for b.Loop() {
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
h.Write(data)
|
h.Write(data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ func TestToECDSAErrors(t *testing.T) {
|
||||||
|
|
||||||
func BenchmarkSha3(b *testing.B) {
|
func BenchmarkSha3(b *testing.B) {
|
||||||
a := []byte("hello world")
|
a := []byte("hello world")
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
Keccak256(a)
|
Keccak256(a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -310,7 +310,7 @@ func BenchmarkKeccak256Hash(b *testing.B) {
|
||||||
rand.Read(input[:])
|
rand.Read(input[:])
|
||||||
|
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
Keccak256Hash(input[:])
|
Keccak256Hash(input[:])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -329,7 +329,7 @@ func BenchmarkHashData(b *testing.B) {
|
||||||
rand.Read(input[:])
|
rand.Read(input[:])
|
||||||
|
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
HashData(buffer, input[:])
|
HashData(buffer, input[:])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,7 @@ func TestTooBigSharedKey(t *testing.T) {
|
||||||
|
|
||||||
// Benchmark the generation of P256 keys.
|
// Benchmark the generation of P256 keys.
|
||||||
func BenchmarkGenerateKeyP256(b *testing.B) {
|
func BenchmarkGenerateKeyP256(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
if _, err := GenerateKey(rand.Reader, elliptic.P256(), nil); err != nil {
|
if _, err := GenerateKey(rand.Reader, elliptic.P256(), nil); err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -177,8 +177,7 @@ func BenchmarkGenSharedKeyP256(b *testing.B) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
b.ResetTimer()
|
for b.Loop() {
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
_, err := prv.GenerateShared(&prv.PublicKey, 16, 16)
|
_, err := prv.GenerateShared(&prv.PublicKey, 16, 16)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
|
|
@ -192,8 +191,7 @@ func BenchmarkGenSharedKeyS256(b *testing.B) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
b.ResetTimer()
|
for b.Loop() {
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
_, err := prv.GenerateShared(&prv.PublicKey, 16, 16)
|
_, err := prv.GenerateShared(&prv.PublicKey, 16, 16)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
|
|
|
||||||
|
|
@ -105,8 +105,7 @@ func benchmarkBlobToCommitment(b *testing.B, ckzg bool) {
|
||||||
|
|
||||||
blob := randBlob()
|
blob := randBlob()
|
||||||
|
|
||||||
b.ResetTimer()
|
for b.Loop() {
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
BlobToCommitment(blob)
|
BlobToCommitment(blob)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -125,8 +124,7 @@ func benchmarkComputeProof(b *testing.B, ckzg bool) {
|
||||||
point = randFieldElement()
|
point = randFieldElement()
|
||||||
)
|
)
|
||||||
|
|
||||||
b.ResetTimer()
|
for b.Loop() {
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
ComputeProof(blob, point)
|
ComputeProof(blob, point)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -147,8 +145,7 @@ func benchmarkVerifyProof(b *testing.B, ckzg bool) {
|
||||||
proof, claim, _ = ComputeProof(blob, point)
|
proof, claim, _ = ComputeProof(blob, point)
|
||||||
)
|
)
|
||||||
|
|
||||||
b.ResetTimer()
|
for b.Loop() {
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
VerifyProof(commitment, point, claim, proof)
|
VerifyProof(commitment, point, claim, proof)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -167,8 +164,7 @@ func benchmarkComputeBlobProof(b *testing.B, ckzg bool) {
|
||||||
commitment, _ = BlobToCommitment(blob)
|
commitment, _ = BlobToCommitment(blob)
|
||||||
)
|
)
|
||||||
|
|
||||||
b.ResetTimer()
|
for b.Loop() {
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
ComputeBlobProof(blob, commitment)
|
ComputeBlobProof(blob, commitment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -188,8 +184,7 @@ func benchmarkVerifyBlobProof(b *testing.B, ckzg bool) {
|
||||||
proof, _ = ComputeBlobProof(blob, commitment)
|
proof, _ = ComputeBlobProof(blob, commitment)
|
||||||
)
|
)
|
||||||
|
|
||||||
b.ResetTimer()
|
for b.Loop() {
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
VerifyBlobProof(blob, commitment, proof)
|
VerifyBlobProof(blob, commitment, proof)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -221,9 +221,7 @@ func TestRecoverSanity(t *testing.T) {
|
||||||
func BenchmarkSign(b *testing.B) {
|
func BenchmarkSign(b *testing.B) {
|
||||||
_, seckey := generateKeyPair()
|
_, seckey := generateKeyPair()
|
||||||
msg := csprngEntropy(32)
|
msg := csprngEntropy(32)
|
||||||
b.ResetTimer()
|
for b.Loop() {
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
Sign(msg, seckey)
|
Sign(msg, seckey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -232,9 +230,7 @@ func BenchmarkRecover(b *testing.B) {
|
||||||
msg := csprngEntropy(32)
|
msg := csprngEntropy(32)
|
||||||
_, seckey := generateKeyPair()
|
_, seckey := generateKeyPair()
|
||||||
sig, _ := Sign(msg, seckey)
|
sig, _ := Sign(msg, seckey)
|
||||||
b.ResetTimer()
|
for b.Loop() {
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
RecoverPubkey(msg, sig)
|
RecoverPubkey(msg, sig)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ func TestPubkeyRandom(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkEcrecoverSignature(b *testing.B) {
|
func BenchmarkEcrecoverSignature(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
if _, err := Ecrecover(testmsg, testsig); err != nil {
|
if _, err := Ecrecover(testmsg, testsig); err != nil {
|
||||||
b.Fatal("ecrecover error", err)
|
b.Fatal("ecrecover error", err)
|
||||||
}
|
}
|
||||||
|
|
@ -144,7 +144,7 @@ func BenchmarkEcrecoverSignature(b *testing.B) {
|
||||||
|
|
||||||
func BenchmarkVerifySignature(b *testing.B) {
|
func BenchmarkVerifySignature(b *testing.B) {
|
||||||
sig := testsig[:len(testsig)-1] // remove recovery id
|
sig := testsig[:len(testsig)-1] // remove recovery id
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
if !VerifySignature(testpubkey, testmsg, sig) {
|
if !VerifySignature(testpubkey, testmsg, sig) {
|
||||||
b.Fatal("verify error")
|
b.Fatal("verify error")
|
||||||
}
|
}
|
||||||
|
|
@ -152,7 +152,7 @@ func BenchmarkVerifySignature(b *testing.B) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkDecompressPubkey(b *testing.B) {
|
func BenchmarkDecompressPubkey(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
if _, err := DecompressPubkey(testpubkeyc); err != nil {
|
if _, err := DecompressPubkey(testpubkeyc); err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue