diff options
author | Sina Ghaderi <khokooli@gmail.com> | 2022-01-23 07:28:42 +0330 |
---|---|---|
committer | Sina Ghaderi <khokooli@gmail.com> | 2022-01-23 07:28:42 +0330 |
commit | 10b8a9ccbd3b3696d643c9798f98e78aaad44c2e (patch) | |
tree | 09f62645a5ff2043b4a6bc3d3c915dc89522727c | |
parent | 42b54e4394977c34c8cf738a1d19f9b37a6a8c5e (diff) |
add benchmark in tests
-rw-r--r-- | io_test.go | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -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") + } + } + }) + +} |