From 10b8a9ccbd3b3696d643c9798f98e78aaad44c2e Mon Sep 17 00:00:00 2001 From: Sina Ghaderi Date: Sun, 23 Jan 2022 07:28:42 +0330 Subject: add benchmark in tests --- io_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) 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") + } + } + }) + +} -- cgit v1.2.3