Open zdyj3170101136 opened 6 months ago
by the way, i tested https://github.com/dataDog/zstd:
func main() {
data, err := os.ReadFile("testdata/test.json")
if err != nil {
panic(err)
}
compress := func() []byte {
result, err := ddzstd.Compress(nil, data)
if err != nil {
panic(err)
}
return result
}
compressed := compress()
decompress := func() {
_, err = ddzstd.Decompress(nil, compressed)
if err != nil {
panic(err)
}
}
for i := 0; i < 100000; i++ {
decompress()
}
}
compress:
real 0m16.081s
user 0m16.398s
sys 0m0.077s
decompress:
real 0m15.462s
user 0m17.649s
sys 0m0.592s
func main() {
data, err := os.ReadFile("testdata/test.json")
if err != nil {
panic(err)
}
compress := func() []byte {
var b bytes.Buffer
w := ddzstd.NewWriter(&b)
w.Write(data)
w.Close()
return b.Bytes()
}
compressed := compress()
decompress := func() {
r := ddzstd.NewReader(bytes.NewReader(compressed))
io.ReadAll(r)
r.Close()
}
for i := 0; i < 10000; i++ {
decompress()
}
}
compress:
real 0m15.020s
user 0m15.481s
sys 0m0.110s
decompress:
real 0m29.116s
user 0m42.343s
sys 0m8.431s
Thanks for the interesting data.
I see that your benchmark is sequential- I wonder what the results would be like for concurrent compression/decompression?
Thanks for the interesting data.
I see that your benchmark is sequential- I wonder what the results would be like for concurrent compression/decompression?
what is your meaning?
the zstd use runtime.GOMAXPROCS(0) to compress and decompress by default.
concurrent compress:
var wg sync.WaitGroup
for j := 0; j < runtime.GOMAXPROCS(0); j++ {
wg.Add(1)
go func() {
defer wg.Done()
for i := 0; i < 10000; i++ {
compress()
}
}()
}
wg.Wait()
benchmark in 32 core machine: zstd stream compress
real 0m23.301s
user 11m44.090s
sys 0m2.399s
zstd encodeAll compress:
real 0m27.575s
user 12m36.868s
sys 0m5.687s
i recommend you replace zstd EncodeAll to zstd stream compress.
@mostynb
i notice you replace zstd.Write to zstd.EncodeAll but without performance compare in https://github.com/mostynb/go-grpc-compression/commit/5f2489304fdefc331e2803e6574af3b8c8f4f00a.
i implement different type of zstd encoding and benchmark it.
1, zstd-stream.
2, zstd. use current package.
benchmark compress code
benchmark compress
use linux time command to execute the program.
zstd-stream:
zstd:
benchmark decompress code
benchmark decompress
use linux time command to execute the program.
zstd-stream:
zstd:
test file
test file is from: https://github.com/klauspost/compress/blob/master/gzip/testdata/test.json