1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-04 11:07:40 +08:00

test: unify tea benchmark

This commit is contained in:
wdvxdr 2021-11-06 14:41:47 +08:00
parent ec0075ebba
commit 7e2033fd75
No known key found for this signature in database
GPG Key ID: 703F8C071DE7A1B6

View File

@ -75,52 +75,57 @@ func TestTEA(t *testing.T) {
}
}
func BenchmarkTEAen16(b *testing.B) {
data := make([]byte, 16)
func benchEncrypt(b *testing.B, data []byte) {
_, err := rand.Read(data)
if err != nil {
panic(err)
}
b.SetBytes(int64(len(data)))
b.ResetTimer()
for i := 0; i < b.N; i++ {
testTEA.Encrypt(data)
}
}
func BenchmarkTEAde16(b *testing.B) {
func benchDecrypt(b *testing.B, data []byte) {
_, err := rand.Read(data)
if err != nil {
panic(err)
}
data = testTEA.Encrypt(data)
b.SetBytes(int64(len(data)))
b.ResetTimer()
for i := 0; i < b.N; i++ {
testTEA.Decrypt(data)
}
}
func BenchmarkTEAen(b *testing.B) {
b.Run("16", func(b *testing.B) {
data := make([]byte, 16)
_, err := rand.Read(data)
if err != nil {
panic(err)
}
data = testTEA.Encrypt(data)
b.ResetTimer()
for i := 0; i < b.N; i++ {
testTEA.Decrypt(data)
}
benchEncrypt(b, data)
})
b.Run("256", func(b *testing.B) {
data := make([]byte, 256)
benchEncrypt(b, data)
})
b.Run("4K", func(b *testing.B) {
data := make([]byte, 4096)
benchEncrypt(b, data)
})
}
func BenchmarkTEAen256(b *testing.B) {
func BenchmarkTEAde(b *testing.B) {
b.Run("16", func(b *testing.B) {
data := make([]byte, 16)
benchDecrypt(b, data)
})
b.Run("256", func(b *testing.B) {
data := make([]byte, 256)
_, err := rand.Read(data)
if err != nil {
panic(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
testTEA.Encrypt(data)
}
}
func BenchmarkTEAde256(b *testing.B) {
data := make([]byte, 256)
_, err := rand.Read(data)
if err != nil {
panic(err)
}
data = testTEA.Encrypt(data)
b.ResetTimer()
for i := 0; i < b.N; i++ {
testTEA.Decrypt(data)
}
benchDecrypt(b, data)
})
b.Run("4K", func(b *testing.B) {
data := make([]byte, 4096)
benchDecrypt(b, data)
})
}