Last active
June 1, 2019 11:06
-
-
Save klauspost/f5df3a3522ac4bcb3bcde448872dffe6 to your computer and use it in GitHub Desktop.
Compression memory test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} | |
}) | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment