diff options
Diffstat (limited to 'io_test.go')
-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") + } + } + }) + +} |