aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSina Ghaderi <khokooli@gmail.com>2022-01-23 07:28:42 +0330
committerSina Ghaderi <khokooli@gmail.com>2022-01-23 07:28:42 +0330
commit10b8a9ccbd3b3696d643c9798f98e78aaad44c2e (patch)
tree09f62645a5ff2043b4a6bc3d3c915dc89522727c
parent42b54e4394977c34c8cf738a1d19f9b37a6a8c5e (diff)
add benchmark in tests
-rw-r--r--io_test.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/io_test.go b/io_test.go
index 582dd1e..dddcf65 100644
--- a/io_test.go
+++ b/io_test.go
@@ -3,6 +3,7 @@ package rabbitio_test
import (
"bytes"
"encoding/hex"
+ "fmt"
"io"
"strings"
"testing"
@@ -103,3 +104,30 @@ func TestNewCipher(t *testing.T) {
}
}
+
+func BenchmarkNewCipher(b *testing.B) {
+ b.Run(fmt.Sprintf("bench %v", b.N), func(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ key, ivt := []byte("12345678abcdefgh"), []byte("1234qwer")
+ txt := "test NewReadercipher text dummy tx"
+ cph, err := rabbitio.NewCipher(key, ivt)
+ if err != nil {
+ b.Fatal(err)
+ }
+ dst := make([]byte, len(txt))
+ cph.XORKeyStream(dst, []byte(txt))
+
+ cph, err = rabbitio.NewCipher(key, ivt)
+ if err != nil {
+ b.Fatal(err)
+ }
+
+ nds := make([]byte, len(dst))
+ cph.XORKeyStream(nds, dst)
+ if string(nds) != txt {
+ b.Error("error: nds is not equal to txt")
+ }
+ }
+ })
+
+}

Snix LLC Git Repository Holder Copyright(C) 2022 All Rights Reserved Email To Snix.IR