mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 19:50:36 +00:00
a8e8bf4528
@shyba hi, seems this lib doesn't work with ghcr.io/goreleaser/goreleaser-cross (which producing release binaries) removing it for now, feel free to add it in future - if can make it work with goreleaser-cross see: https://github.com/ledgerwatch/erigon/issues/7210
47 lines
790 B
Go
47 lines
790 B
Go
package vtree
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"math/big"
|
|
"math/rand"
|
|
"testing"
|
|
)
|
|
|
|
func BenchmarkPedersenHash(b *testing.B) {
|
|
var addr, v [32]byte
|
|
|
|
b.ResetTimer()
|
|
b.ReportAllocs()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
rand.Read(v[:])
|
|
rand.Read(addr[:])
|
|
GetTreeKeyCodeSize(addr[:])
|
|
}
|
|
}
|
|
|
|
func sha256GetTreeKeyCodeSize(addr []byte) []byte {
|
|
digest := sha256.New()
|
|
digest.Write(addr)
|
|
treeIndexBytes := new(big.Int).Bytes()
|
|
var payload [32]byte
|
|
copy(payload[:len(treeIndexBytes)], treeIndexBytes)
|
|
digest.Write(payload[:])
|
|
h := digest.Sum(nil)
|
|
h[31] = CodeKeccakLeafKey
|
|
return h
|
|
}
|
|
|
|
func BenchmarkSha256Hash(b *testing.B) {
|
|
var addr, v [32]byte
|
|
|
|
b.ResetTimer()
|
|
b.ReportAllocs()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
rand.Read(v[:])
|
|
rand.Read(addr[:])
|
|
sha256GetTreeKeyCodeSize(addr[:])
|
|
}
|
|
}
|