goProject/trunk/goutil/lz4Util/lz4_test.go

65 lines
1.3 KiB
Go
Raw Normal View History

2025-01-06 16:01:02 +08:00
package lz4Util
import (
"fmt"
"strings"
"testing"
)
var (
InitString = `{"Code":4,"Message":"IPNotAuthorized","Data":null}`
CompressBytes []byte
)
//正确性测试
func TestCompress(t *testing.T){
s := "hello world"
repeatCount:= 1000
toCompress := []byte(strings.Repeat(s, repeatCount))
compressed,err := Compress(toCompress)
if err!=nil{
fmt.Println(err)
}
fmt.Println("compressed Data:", string(compressed))
//decompress
decompressed,err := Decompress(compressed)
if err!=nil{
fmt.Println(err)
}
if strings.Repeat(s, repeatCount)!=string(decompressed){
fmt.Println("有问题")
}else{
fmt.Println("没问题")
}
fmt.Println("\ndecompressed Data:", string(decompressed))
}
//BenchmarkCompress-12 28647 37948 ns/op
func BenchmarkCompress(b *testing.B) {
toCompress := []byte(strings.Repeat(InitString, 100))
b.ResetTimer()
for i := 0; i < b.N; i++ {
_,err := Compress(toCompress)
if err!=nil{
b.Log(err)
}
}
b.StopTimer()
}
//BenchmarkDeCompress-12 267382 4127 ns/op
func BenchmarkDeCompress(b *testing.B) {
toCompress := []byte(strings.Repeat(InitString, 100))
compressedData,_ := Compress(toCompress)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_,err := Decompress(compressedData)
if err!=nil{
b.Log(err)
}
}
b.StopTimer()
}