diff options
Diffstat (limited to 'libgo/go/compress/lzw/writer_test.go')
-rw-r--r-- | libgo/go/compress/lzw/writer_test.go | 55 |
1 files changed, 25 insertions, 30 deletions
diff --git a/libgo/go/compress/lzw/writer_test.go b/libgo/go/compress/lzw/writer_test.go index 66d761727f..4979f8b352 100644 --- a/libgo/go/compress/lzw/writer_test.go +++ b/libgo/go/compress/lzw/writer_test.go @@ -5,9 +5,11 @@ package lzw import ( + "fmt" "internal/testenv" "io" "io/ioutil" + "math" "os" "runtime" "testing" @@ -122,41 +124,34 @@ func TestSmallLitWidth(t *testing.T) { } } -func benchmarkEncoder(b *testing.B, n int) { - b.StopTimer() - b.SetBytes(int64(n)) - buf0, err := ioutil.ReadFile("../testdata/e.txt") +func BenchmarkEncoder(b *testing.B) { + buf, err := ioutil.ReadFile("../testdata/e.txt") if err != nil { b.Fatal(err) } - if len(buf0) == 0 { + if len(buf) == 0 { b.Fatalf("test file has no data") } - buf1 := make([]byte, n) - for i := 0; i < n; i += len(buf0) { - if len(buf0) > n-i { - buf0 = buf0[:n-i] + + for e := 4; e <= 6; e++ { + n := int(math.Pow10(e)) + buf0 := buf + buf1 := make([]byte, n) + for i := 0; i < n; i += len(buf0) { + if len(buf0) > n-i { + buf0 = buf0[:n-i] + } + copy(buf1[i:], buf0) } - copy(buf1[i:], buf0) - } - buf0 = nil - runtime.GC() - b.StartTimer() - for i := 0; i < b.N; i++ { - w := NewWriter(ioutil.Discard, LSB, 8) - w.Write(buf1) - w.Close() + buf0 = nil + runtime.GC() + b.Run(fmt.Sprint("1e", e), func(b *testing.B) { + b.SetBytes(int64(n)) + for i := 0; i < b.N; i++ { + w := NewWriter(ioutil.Discard, LSB, 8) + w.Write(buf1) + w.Close() + } + }) } } - -func BenchmarkEncoder1e4(b *testing.B) { - benchmarkEncoder(b, 1e4) -} - -func BenchmarkEncoder1e5(b *testing.B) { - benchmarkEncoder(b, 1e5) -} - -func BenchmarkEncoder1e6(b *testing.B) { - benchmarkEncoder(b, 1e6) -} |