Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: compression benchmarks #678

Merged
merged 3 commits into from
Oct 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions compress/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,85 @@ 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 562878 2031 ns/op 448 B/op 1 allocs/op
BenchmarkDecompress/zstd-cgo/default-24 506319 2210 ns/op 448 B/op 1 allocs/op
BenchmarkDecompress/zstd-cgo/best-24 526634 2198 ns/op 448 B/op 1 allocs/op
*/
func BenchmarkDecompress(b *testing.B) {
b.Run("zstd-cgo", func(b *testing.B) {
b.Run("fastest", func(b *testing.B) {
b.ReportAllocs()
c, _ := New(CompressionAlgoZstdCgo, CompressionLevelZstdCgoFastest)
r, _ := c.Compress(loremIpsumDolor)
defer func() { _ = c.Close() }()

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

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

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