-
Notifications
You must be signed in to change notification settings - Fork 13
/
compress_test.go
68 lines (57 loc) · 4.27 KB
/
compress_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package nsq
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestCompressDecompressSnappy(t *testing.T) {
forCompress := "this is text for compress"
testCompressDecompress([]byte(forCompress), CompressDecodec_SNAPPY, t)
}
func TestCompressDecompressGZIP(t *testing.T) {
forCompress := "this is text for compress"
testCompressDecompress([]byte(forCompress), CompressDecodec_GZIP, t)
}
func TestCompressDecompressLZ4(t *testing.T) {
forCompress := "Fast compression/decompression around 200~400MB/sec.Less memory usage. SnappyOutputStream uses only 32KB+ in default.JNI-based implementation to achieve comparable performance to the native C++ version.Although snappy-java uses JNI, it can be used safely with multiple class loaders (e.g. Tomcat, etc.)."
testCompressDecompress([]byte(forCompress), CompressDecodec_LZ4, t)
}
func testCompressDecompress(forCompress []byte, codec NSQClientCompressCodec, t *testing.T) {
compressed, err := codec.Compress(forCompress)
assert.Nil(t, err)
decompressed, err := codec.Decompress(compressed, len(compressed)*10)
assert.Nil(t, err)
assert.EqualValues(t, len(forCompress), len(decompressed))
assert.EqualValues(t, forCompress, decompressed)
}
func TestCompressDecompressSnappyBlock(t *testing.T) {
forCompress := "this is text for compress"
testCompressDecompress([]byte(forCompress), CompressDecodec_SNAPPY, t)
}
func BenchmarkCompressSnappyBlock(b *testing.B) {
forCompress := []byte("Provides stream classes for the LZ4 algorithm.The block LZ4 format which only contains the compressed data is supported by the BlockLZ4Compressor*putStream classes while the frame format is implemented by FramedLZ4Compressor*putStream. The implementation in Commons Compress is based on the specifications \"Last revised: 2015-03-26\" for the block format and version \"1.5.1 (31/03/2015)\" for the frame format.Only the frame format can be auto-detected this means you have to speficy the format explicitly if you want to read a block LZ4 stream via CompressorStreamFactory.")
for i := 0; i < b.N; i++ {
_, err := CompressDecodec_SNAPPY.Compress(forCompress)
assert.Nil(b, err)
}
}
func BenchmarkCompressSnappy(b *testing.B) {
forCompress := []byte("Provides stream classes for the LZ4 algorithm.The block LZ4 format which only contains the compressed data is supported by the BlockLZ4Compressor*putStream classes while the frame format is implemented by FramedLZ4Compressor*putStream. The implementation in Commons Compress is based on the specifications \"Last revised: 2015-03-26\" for the block format and version \"1.5.1 (31/03/2015)\" for the frame format.Only the frame format can be auto-detected this means you have to speficy the format explicitly if you want to read a block LZ4 stream via CompressorStreamFactory.")
for i := 0; i < b.N; i++ {
_, err := compressSnappy(forCompress)
assert.Nil(b, err)
}
}
func BenchmarkCompressLZ4Block(b *testing.B) {
forCompress := []byte("Provides stream classes for the LZ4 algorithm.The block LZ4 format which only contains the compressed data is supported by the BlockLZ4Compressor*putStream classes while the frame format is implemented by FramedLZ4Compressor*putStream. The implementation in Commons Compress is based on the specifications \"Last revised: 2015-03-26\" for the block format and version \"1.5.1 (31/03/2015)\" for the frame format.Only the frame format can be auto-detected this means you have to speficy the format explicitly if you want to read a block LZ4 stream via CompressorStreamFactory.")
for i := 0; i < b.N; i++ {
_, err := compressLZ4Block(forCompress)
assert.Nil(b, err)
}
}
func BenchmarkCompressLZ4(b *testing.B) {
forCompress := []byte("Provides stream classes for the LZ4 algorithm.The block LZ4 format which only contains the compressed data is supported by the BlockLZ4Compressor*putStream classes while the frame format is implemented by FramedLZ4Compressor*putStream. The implementation in Commons Compress is based on the specifications \"Last revised: 2015-03-26\" for the block format and version \"1.5.1 (31/03/2015)\" for the frame format.Only the frame format can be auto-detected this means you have to speficy the format explicitly if you want to read a block LZ4 stream via CompressorStreamFactory.")
for i := 0; i < b.N; i++ {
_, err := compressLZ4(forCompress)
assert.Nil(b, err)
}
}