MCPcopy
hub / github.com/dgraph-io/dgraph / BenchmarkGzip

Function BenchmarkGzip

codec/codec_test.go:219–249  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

217}
218
219func BenchmarkGzip(b *testing.B) {
220 uids := getUids(1e6)
221 b.ResetTimer()
222 sz := uint64(len(uids)) * 8
223
224 b.Logf("Dataset Len=%d. Size: %s", len(uids), humanize.Bytes(sz))
225 var data []byte
226 for i := 0; i < b.N; i++ {
227 tmp := make([]byte, binary.MaxVarintLen64)
228 var buf bytes.Buffer
229 for _, uid := range uids {
230 n := binary.PutUvarint(tmp, uid)
231 _, err := buf.Write(tmp[:n])
232 if err != nil {
233 b.Fatalf("Error while writing to buffer: %s", err.Error())
234 }
235 }
236
237 var out bytes.Buffer
238 zw := gzip.NewWriter(&out)
239 _, err := zw.Write(buf.Bytes())
240 if err != nil {
241 b.Fatalf("Error while writing to gzip writer: %s", err.Error())
242 }
243
244 data = out.Bytes()
245 }
246 b.Logf("Output size: %s. Compression: %.2f",
247 humanize.Bytes(uint64(len(data))),
248 float64(len(data))/float64(sz))
249}
250
251func benchmarkUidPackEncode(b *testing.B, blockSize int) {
252 uids := getUids(1e6)

Callers

nothing calls this directly

Calls 5

WriteMethod · 0.95
getUidsFunction · 0.85
FatalfMethod · 0.80
WriteMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected