Skip to content

Commit

Permalink
Merge pull request #107 from klauspost/leaner-interface-pt2
Browse files Browse the repository at this point in the history
deflate: Move advanced compression state
  • Loading branch information
klauspost committed Jun 5, 2019
2 parents 811ecb2 + a76fe6f commit 8665cc6
Show file tree
Hide file tree
Showing 4 changed files with 324 additions and 272 deletions.
38 changes: 38 additions & 0 deletions compressible_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ package compress
import (
"crypto/rand"
"encoding/base32"
"io/ioutil"
"strconv"
"strings"
"testing"

"github.com/klauspost/compress/flate"
"github.com/klauspost/compress/gzip"
)

func BenchmarkEstimate(b *testing.B) {
Expand Down Expand Up @@ -233,3 +239,35 @@ Thoughts?`)
b.Log(SnannonEntropyBits(testData))
})
}

func BenchmarkCompressAllocations(b *testing.B) {
payload := []byte(strings.Repeat("Tiny payload", 20))
for j := -2; j <= 9; j++ {
b.Run("level("+strconv.Itoa(j)+")", func(b *testing.B) {
b.Run("flate", func(b *testing.B) {
b.ReportAllocs()

for i := 0; i < b.N; i++ {
w, err := flate.NewWriter(ioutil.Discard, j)
if err != nil {
b.Fatal(err)
}
w.Write(payload)
w.Close()
}
})
b.Run("gzip", func(b *testing.B) {
b.ReportAllocs()

for i := 0; i < b.N; i++ {
w, err := gzip.NewWriterLevel(ioutil.Discard, j)
if err != nil {
b.Fatal(err)
}
w.Write(payload)
w.Close()
}
})
})
}
}
Loading

0 comments on commit 8665cc6

Please sign in to comment.