aboutsummaryrefslogtreecommitdiffstats
path: root/whisper/whisperv6/benchmarks_test.go
diff options
context:
space:
mode:
authorgluk256 <gluk256@users.noreply.github.com>2017-11-04 04:29:49 +0800
committerFelix Lange <fjl@users.noreply.github.com>2017-11-04 04:29:49 +0800
commit9f7cd7568275e2db45a3d90429f7c92bf7dfbf19 (patch)
treee3fd637e6cd7b9968b4bedb030959167e299c136 /whisper/whisperv6/benchmarks_test.go
parent0131bd6ff9b1850fdd307715c62174af4f05d2c7 (diff)
downloaddexon-9f7cd7568275e2db45a3d90429f7c92bf7dfbf19.tar
dexon-9f7cd7568275e2db45a3d90429f7c92bf7dfbf19.tar.gz
dexon-9f7cd7568275e2db45a3d90429f7c92bf7dfbf19.tar.bz2
dexon-9f7cd7568275e2db45a3d90429f7c92bf7dfbf19.tar.lz
dexon-9f7cd7568275e2db45a3d90429f7c92bf7dfbf19.tar.xz
dexon-9f7cd7568275e2db45a3d90429f7c92bf7dfbf19.tar.zst
dexon-9f7cd7568275e2db45a3d90429f7c92bf7dfbf19.zip
whisper/whisperv6: initial commit (clone of v5) (#15324)
Diffstat (limited to 'whisper/whisperv6/benchmarks_test.go')
-rw-r--r--whisper/whisperv6/benchmarks_test.go206
1 files changed, 206 insertions, 0 deletions
diff --git a/whisper/whisperv6/benchmarks_test.go b/whisper/whisperv6/benchmarks_test.go
new file mode 100644
index 000000000..9f413e7b0
--- /dev/null
+++ b/whisper/whisperv6/benchmarks_test.go
@@ -0,0 +1,206 @@
+// Copyright 2016 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 whisperv6
+
+import (
+ "testing"
+
+ "github.com/ethereum/go-ethereum/crypto"
+)
+
+func BenchmarkDeriveKeyMaterial(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ deriveKeyMaterial([]byte("test"), 0)
+ }
+}
+
+func BenchmarkEncryptionSym(b *testing.B) {
+ InitSingleTest()
+
+ params, err := generateMessageParams()
+ if err != nil {
+ b.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
+ }
+
+ for i := 0; i < b.N; i++ {
+ msg, _ := NewSentMessage(params)
+ _, err := msg.Wrap(params)
+ if err != nil {
+ b.Errorf("failed Wrap with seed %d: %s.", seed, err)
+ b.Errorf("i = %d, len(msg.Raw) = %d, params.Payload = %d.", i, len(msg.Raw), len(params.Payload))
+ return
+ }
+ }
+}
+
+func BenchmarkEncryptionAsym(b *testing.B) {
+ InitSingleTest()
+
+ params, err := generateMessageParams()
+ if err != nil {
+ b.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
+ }
+ key, err := crypto.GenerateKey()
+ if err != nil {
+ b.Fatalf("failed GenerateKey with seed %d: %s.", seed, err)
+ }
+ params.KeySym = nil
+ params.Dst = &key.PublicKey
+
+ for i := 0; i < b.N; i++ {
+ msg, _ := NewSentMessage(params)
+ _, err := msg.Wrap(params)
+ if err != nil {
+ b.Fatalf("failed Wrap with seed %d: %s.", seed, err)
+ }
+ }
+}
+
+func BenchmarkDecryptionSymValid(b *testing.B) {
+ InitSingleTest()
+
+ params, err := generateMessageParams()
+ if err != nil {
+ b.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
+ }
+ msg, _ := NewSentMessage(params)
+ env, err := msg.Wrap(params)
+ if err != nil {
+ b.Fatalf("failed Wrap with seed %d: %s.", seed, err)
+ }
+ f := Filter{KeySym: params.KeySym}
+
+ for i := 0; i < b.N; i++ {
+ msg := env.Open(&f)
+ if msg == nil {
+ b.Fatalf("failed to open with seed %d.", seed)
+ }
+ }
+}
+
+func BenchmarkDecryptionSymInvalid(b *testing.B) {
+ InitSingleTest()
+
+ params, err := generateMessageParams()
+ if err != nil {
+ b.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
+ }
+ msg, _ := NewSentMessage(params)
+ env, err := msg.Wrap(params)
+ if err != nil {
+ b.Fatalf("failed Wrap with seed %d: %s.", seed, err)
+ }
+ f := Filter{KeySym: []byte("arbitrary stuff here")}
+
+ for i := 0; i < b.N; i++ {
+ msg := env.Open(&f)
+ if msg != nil {
+ b.Fatalf("opened envelope with invalid key, seed: %d.", seed)
+ }
+ }
+}
+
+func BenchmarkDecryptionAsymValid(b *testing.B) {
+ InitSingleTest()
+
+ params, err := generateMessageParams()
+ if err != nil {
+ b.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
+ }
+ key, err := crypto.GenerateKey()
+ if err != nil {
+ b.Fatalf("failed GenerateKey with seed %d: %s.", seed, err)
+ }
+ f := Filter{KeyAsym: key}
+ params.KeySym = nil
+ params.Dst = &key.PublicKey
+ msg, _ := NewSentMessage(params)
+ env, err := msg.Wrap(params)
+ if err != nil {
+ b.Fatalf("failed Wrap with seed %d: %s.", seed, err)
+ }
+
+ for i := 0; i < b.N; i++ {
+ msg := env.Open(&f)
+ if msg == nil {
+ b.Fatalf("fail to open, seed: %d.", seed)
+ }
+ }
+}
+
+func BenchmarkDecryptionAsymInvalid(b *testing.B) {
+ InitSingleTest()
+
+ params, err := generateMessageParams()
+ if err != nil {
+ b.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
+ }
+ key, err := crypto.GenerateKey()
+ if err != nil {
+ b.Fatalf("failed GenerateKey with seed %d: %s.", seed, err)
+ }
+ params.KeySym = nil
+ params.Dst = &key.PublicKey
+ msg, _ := NewSentMessage(params)
+ env, err := msg.Wrap(params)
+ if err != nil {
+ b.Fatalf("failed Wrap with seed %d: %s.", seed, err)
+ }
+
+ key, err = crypto.GenerateKey()
+ if err != nil {
+ b.Fatalf("failed GenerateKey with seed %d: %s.", seed, err)
+ }
+ f := Filter{KeyAsym: key}
+
+ for i := 0; i < b.N; i++ {
+ msg := env.Open(&f)
+ if msg != nil {
+ b.Fatalf("opened envelope with invalid key, seed: %d.", seed)
+ }
+ }
+}
+
+func increment(x []byte) {
+ for i := 0; i < len(x); i++ {
+ x[i]++
+ if x[i] != 0 {
+ break
+ }
+ }
+}
+
+func BenchmarkPoW(b *testing.B) {
+ InitSingleTest()
+
+ params, err := generateMessageParams()
+ if err != nil {
+ b.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
+ }
+ params.Payload = make([]byte, 32)
+ params.PoW = 10.0
+ params.TTL = 1
+
+ for i := 0; i < b.N; i++ {
+ increment(params.Payload)
+ msg, _ := NewSentMessage(params)
+ _, err := msg.Wrap(params)
+ if err != nil {
+ b.Fatalf("failed Wrap with seed %d: %s.", seed, err)
+ }
+ }
+}