mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 22:26:42 +00:00
crypto, core: add benchmarks
This commit is contained in:
parent
79d33f3cc5
commit
3df73a850c
2 changed files with 36 additions and 17 deletions
|
|
@ -1,17 +0,0 @@
|
|||
// Copyright 2017 The go-ethereum Authors
|
||||
// This file is part of the go-ethereum library.
|
||||
//
|
||||
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package rawdb
|
||||
|
|
@ -19,6 +19,7 @@ package crypto
|
|||
import (
|
||||
"bytes"
|
||||
"crypto/ecdsa"
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"math/big"
|
||||
"os"
|
||||
|
|
@ -297,3 +298,38 @@ func TestPythonIntegration(t *testing.T) {
|
|||
t.Logf("msg: %x, privkey: %s sig: %x\n", msg0, kh, sig0)
|
||||
t.Logf("msg: %x, privkey: %s sig: %x\n", msg1, kh, sig1)
|
||||
}
|
||||
|
||||
// goos: darwin
|
||||
// goarch: arm64
|
||||
// pkg: github.com/ethereum/go-ethereum/crypto
|
||||
// cpu: Apple M1 Pro
|
||||
// BenchmarkKeccak256Hash
|
||||
// BenchmarkKeccak256Hash-8 931095 1270 ns/op 32 B/op 1 allocs/op
|
||||
func BenchmarkKeccak256Hash(b *testing.B) {
|
||||
var input [512]byte
|
||||
rand.Read(input[:])
|
||||
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
Keccak256Hash(input[:])
|
||||
}
|
||||
}
|
||||
|
||||
// goos: darwin
|
||||
// goarch: arm64
|
||||
// pkg: github.com/ethereum/go-ethereum/crypto
|
||||
// cpu: Apple M1 Pro
|
||||
// BenchmarkHashData
|
||||
// BenchmarkHashData-8 793386 1278 ns/op 32 B/op 1 allocs/op
|
||||
func BenchmarkHashData(b *testing.B) {
|
||||
var (
|
||||
input [512]byte
|
||||
buffer = NewKeccakState()
|
||||
)
|
||||
rand.Read(input[:])
|
||||
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
HashData(buffer, input[:])
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue