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

Microbenchmark for compression #275

Merged
merged 1 commit into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ require (
github.com/spf13/cobra v0.0.3
github.com/spf13/pflag v1.0.3 // indirect
github.com/stretchr/testify v1.4.0
github.com/yahoo/athenz v1.8.55
github.com/valyala/gozstd v1.7.0
github.com/yahoo/athenz v1.8.55
)
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ github.com/jawher/mow.cli v1.0.4/go.mod h1:5hQj2V8g+qYmLUVWqu4Wuja1pI57M83EChYLV
github.com/jawher/mow.cli v1.1.0/go.mod h1:aNaQlc7ozF3vw6IJ2dHjp2ZFiA4ozMIYY6PyuRJwlUg=
github.com/klauspost/compress v1.10.5 h1:7q6vHIqubShURwQz8cQK6yIe/xC3IF0Vm7TGfqjewrc=
github.com/klauspost/compress v1.10.5/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/compress v1.10.8 h1:eLeJ3dr/Y9+XRfJT4l+8ZjmtB5RPJhucH2HeCV5+IZY=
github.com/klauspost/compress v1.10.8/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
Expand Down
92 changes: 92 additions & 0 deletions pulsar/internal/compression/compression_bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package compression

import (
"io/ioutil"
"testing"
)

var compressed int

func testCompression(b *testing.B, provider Provider) {
data, err := ioutil.ReadFile("test_data_sample.txt")
if err != nil {
b.Error(err)
}

dataLen := int64(len(data))

b.ResetTimer()

for i := 0; i < b.N; i++ {
// Use len() to avoid the compiler optimizing the call away
compressed = len(provider.Compress(data))
b.SetBytes(dataLen)
}
}

func testDecompression(b *testing.B, provider Provider) {
// Read data sample file
data, err := ioutil.ReadFile("test_data_sample.txt")
if err != nil {
b.Error(err)
}

dataCompressed := provider.Compress(data)

dataLen := int64(len(data))

b.ResetTimer()

for i := 0; i < b.N; i++ {
provider.Decompress(dataCompressed, int(dataLen))
b.SetBytes(dataLen)
}
}

var benchmarkProviders = []testProvider{
{"zlib", ZLibProvider, nil},
{"lz4", Lz4Provider, nil},
{"zstd-pure-go-fastest", newPureGoZStdProvider(1), nil},
{"zstd-pure-go-default", newPureGoZStdProvider(2), nil},
{"zstd-pure-go-best", newPureGoZStdProvider(3), nil},
{"zstd-cgo-level-fastest", newCGoZStdProvider(1), nil},
{"zstd-cgo-level-default", newCGoZStdProvider(3), nil},
{"zstd-cgo-level-best", newCGoZStdProvider(9), nil},
}

func BenchmarkCompression(b *testing.B) {
b.ReportAllocs()
for _, provider := range benchmarkProviders {
p := provider
b.Run(p.name, func(b *testing.B) {
testCompression(b, p.provider)
})
}
}

func BenchmarkDecompression(b *testing.B) {
b.ReportAllocs()
for _, provider := range benchmarkProviders {
p := provider
b.Run(p.name, func(b *testing.B) {
testDecompression(b, p.provider)
})
}
}
Loading