1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
// Copyright 2015, Joe Tsai. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE.md file.
package bzip2
import (
"bytes"
"io"
"io/ioutil"
"testing"
)
func BenchmarkEncode(b *testing.B) {
runBenchmarks(b, func(b *testing.B, data []byte, lvl int) {
b.StopTimer()
b.ReportAllocs()
br := new(bytes.Reader)
wr, _ := NewWriter(nil, &WriterConfig{Level: lvl})
b.SetBytes(int64(len(data)))
b.StartTimer()
for i := 0; i < b.N; i++ {
br.Reset(data)
wr.Reset(ioutil.Discard)
n, err := io.Copy(wr, br)
if n != int64(len(data)) || err != nil {
b.Fatalf("Copy() = (%d, %v), want (%d, nil)", n, err, len(data))
}
if err := wr.Close(); err != nil {
b.Fatalf("Close() = %v, want nil", err)
}
}
})
}
|