Skip to content

Commit

Permalink
chore: compression benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
fracasula committed Oct 23, 2024
1 parent 50d8320 commit 0bb6a9f
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions compress/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,83 @@ func BenchmarkNew(b *testing.B) {
}
})
}

/*
BenchmarkCompress/zstd-cgo/fastest-24 330330 3634 ns/op 512 B/op 1 allocs/op
BenchmarkCompress/zstd-cgo/default-24 205960 5673 ns/op 512 B/op 1 allocs/op
BenchmarkCompress/zstd-cgo/best-24 51088 23294 ns/op 512 B/op 1 allocs/op
*/
func BenchmarkCompress(b *testing.B) {
b.Run("zstd-cgo", func(b *testing.B) {
b.Run("fastest", func(b *testing.B) {
b.ReportAllocs()
c, _ := New(CompressionAlgoZstdCgo, CompressionLevelZstdCgoFastest)
defer func() { _ = c.Close() }()

for i := 0; i < b.N; i++ {
_, _ = c.Compress(loremIpsumDolor)
}
})
b.Run("default", func(b *testing.B) {
b.ReportAllocs()
c, _ := New(CompressionAlgoZstdCgo, CompressionLevelZstdCgoDefault)
defer func() { _ = c.Close() }()

for i := 0; i < b.N; i++ {
_, _ = c.Compress(loremIpsumDolor)
}
})
b.Run("best", func(b *testing.B) {
b.ReportAllocs()
c, _ := New(CompressionAlgoZstdCgo, CompressionLevelZstdCgoBest)
defer func() { _ = c.Close() }()

for i := 0; i < b.N; i++ {
_, _ = c.Compress(loremIpsumDolor)
}
})
})
}

/*
Benchmark to prove that no matter the compression level, the decompression always takes the same time.
BenchmarkDecompress/zstd-cgo/fastest-24 518247 2217 ns/op 448 B/op 1 allocs/op
BenchmarkDecompress/zstd-cgo/default-24 528907 2199 ns/op 448 B/op 1 allocs/op
BenchmarkDecompress/zstd-cgo/best-24 527167 2208 ns/op 448 B/op 1 allocs/op
*/
func BenchmarkDecompress(b *testing.B) {
b.Run("zstd-cgo", func(b *testing.B) {
c, _ := New(CompressionAlgoZstdCgo, CompressionLevelZstdCgoBest)
r, _ := c.Compress(loremIpsumDolor)
_ = c.Close()

b.Run("fastest", func(b *testing.B) {
b.ReportAllocs()
c, _ := New(CompressionAlgoZstdCgo, CompressionLevelZstdCgoFastest)
defer func() { _ = c.Close() }()

for i := 0; i < b.N; i++ {
_, _ = c.Decompress(r)
}
})
b.Run("default", func(b *testing.B) {
b.ReportAllocs()
c, _ := New(CompressionAlgoZstdCgo, CompressionLevelZstdCgoDefault)
defer func() { _ = c.Close() }()

for i := 0; i < b.N; i++ {
_, _ = c.Decompress(r)
}
})
b.Run("best", func(b *testing.B) {
b.ReportAllocs()
c, _ := New(CompressionAlgoZstdCgo, CompressionLevelZstdCgoBest)
defer func() { _ = c.Close() }()

for i := 0; i < b.N; i++ {
_, _ = c.Decompress(r)
}
})
})
}

0 comments on commit 0bb6a9f

Please sign in to comment.