Skip to content

Conversation

cuiweixie
Copy link
Contributor

func BenchmarkTextHash(b *testing.B) {
	// warm up
	_ = TextHash([]byte("Hello Joe"))

	for b.Loop() {
		_ = TextHash([]byte("Hello Joe"))
	}
}
goos: darwin
goarch: arm64
pkg: github.com/ethereum/go-ethereum/accounts
cpu: Apple M1 Pro
            │   old.txt   │              new.txt               │
            │   sec/op    │   sec/op     vs base               │
TextHash-10   505.1n ± 1%   484.2n ± 0%  -4.15% (p=0.000 n=10)

            │  old.txt   │              new.txt               │
            │    B/op    │    B/op     vs base                │
TextHash-10   168.0 ± 0%   120.0 ± 0%  -28.57% (p=0.000 n=10)

            │  old.txt   │              new.txt               │
            │ allocs/op  │ allocs/op   vs base                │
TextHash-10   5.000 ± 0%   4.000 ± 0%  -20.00% (p=0.000 n=10)

// This gives context to the signed message and prevents signing of transactions.
func TextAndHash(data []byte) ([]byte, string) {
msg := fmt.Sprintf("\x19Ethereum Signed Message:\n%d%s", len(data), data)
hasher := sha3.NewLegacyKeccak256()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not performance critical. I prefer to not use the unsafe here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants