diff options
author | Ondřej Surý <ondrej@sury.org> | 2011-04-26 09:55:32 +0200 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2011-04-26 09:55:32 +0200 |
commit | 7b15ed9ef455b6b66c6b376898a88aef5d6a9970 (patch) | |
tree | 3ef530baa80cdf29436ba981f5783be6b4d2202b /src/pkg/compress | |
parent | 50104cc32a498f7517a51c8dc93106c51c7a54b4 (diff) | |
download | golang-7b15ed9ef455b6b66c6b376898a88aef5d6a9970.tar.gz |
Imported Upstream version 2011.04.13upstream/2011.04.13
Diffstat (limited to 'src/pkg/compress')
-rw-r--r-- | src/pkg/compress/lzw/reader_test.go | 23 | ||||
-rw-r--r-- | src/pkg/compress/lzw/writer_test.go | 31 | ||||
-rw-r--r-- | src/pkg/compress/zlib/writer_test.go | 4 |
3 files changed, 49 insertions, 9 deletions
diff --git a/src/pkg/compress/lzw/reader_test.go b/src/pkg/compress/lzw/reader_test.go index 7795a4c14..4b5dfaade 100644 --- a/src/pkg/compress/lzw/reader_test.go +++ b/src/pkg/compress/lzw/reader_test.go @@ -9,6 +9,7 @@ import ( "io" "io/ioutil" "os" + "runtime" "strconv" "strings" "testing" @@ -117,16 +118,34 @@ func (devNull) Write(p []byte) (int, os.Error) { return len(p), nil } -func BenchmarkDecoder(b *testing.B) { +func benchmarkDecoder(b *testing.B, n int) { b.StopTimer() + b.SetBytes(int64(n)) buf0, _ := ioutil.ReadFile("../testdata/e.txt") + buf0 = buf0[:10000] compressed := bytes.NewBuffer(nil) w := NewWriter(compressed, LSB, 8) - io.Copy(w, bytes.NewBuffer(buf0)) + for i := 0; i < n; i += len(buf0) { + io.Copy(w, bytes.NewBuffer(buf0)) + } w.Close() buf1 := compressed.Bytes() + buf0, compressed, w = nil, nil, nil + runtime.GC() b.StartTimer() for i := 0; i < b.N; i++ { io.Copy(devNull{}, NewReader(bytes.NewBuffer(buf1), LSB, 8)) } } + +func BenchmarkDecoder1e4(b *testing.B) { + benchmarkDecoder(b, 1e4) +} + +func BenchmarkDecoder1e5(b *testing.B) { + benchmarkDecoder(b, 1e5) +} + +func BenchmarkDecoder1e6(b *testing.B) { + benchmarkDecoder(b, 1e6) +} diff --git a/src/pkg/compress/lzw/writer_test.go b/src/pkg/compress/lzw/writer_test.go index 715b974aa..e5815a03d 100644 --- a/src/pkg/compress/lzw/writer_test.go +++ b/src/pkg/compress/lzw/writer_test.go @@ -8,6 +8,7 @@ import ( "io" "io/ioutil" "os" + "runtime" "testing" ) @@ -20,7 +21,7 @@ var filenames = []string{ // the given options yields equivalent bytes to the original file. func testFile(t *testing.T, fn string, order Order, litWidth int) { // Read the file, as golden output. - golden, err := os.Open(fn, os.O_RDONLY, 0400) + golden, err := os.Open(fn) if err != nil { t.Errorf("%s (order=%d litWidth=%d): %v", fn, order, litWidth, err) return @@ -28,7 +29,7 @@ func testFile(t *testing.T, fn string, order Order, litWidth int) { defer golden.Close() // Read the file again, and push it through a pipe that compresses at the write end, and decompresses at the read end. - raw, err := os.Open(fn, os.O_RDONLY, 0400) + raw, err := os.Open(fn) if err != nil { t.Errorf("%s (order=%d litWidth=%d): %v", fn, order, litWidth, err) return @@ -99,13 +100,33 @@ func TestWriter(t *testing.T) { } } -func BenchmarkEncoder(b *testing.B) { +func benchmarkEncoder(b *testing.B, n int) { b.StopTimer() - buf, _ := ioutil.ReadFile("../testdata/e.txt") + b.SetBytes(int64(n)) + buf0, _ := ioutil.ReadFile("../testdata/e.txt") + buf0 = buf0[:10000] + buf1 := make([]byte, n) + for i := 0; i < n; i += len(buf0) { + copy(buf1[i:], buf0) + } + buf0 = nil + runtime.GC() b.StartTimer() for i := 0; i < b.N; i++ { w := NewWriter(devNull{}, LSB, 8) - w.Write(buf) + 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) +} diff --git a/src/pkg/compress/zlib/writer_test.go b/src/pkg/compress/zlib/writer_test.go index 5a13ba825..7eb1cd494 100644 --- a/src/pkg/compress/zlib/writer_test.go +++ b/src/pkg/compress/zlib/writer_test.go @@ -20,7 +20,7 @@ var filenames = []string{ // yields equivalent bytes to the original file. func testFileLevel(t *testing.T, fn string, level int) { // Read the file, as golden output. - golden, err := os.Open(fn, os.O_RDONLY, 0444) + golden, err := os.Open(fn) if err != nil { t.Errorf("%s (level=%d): %v", fn, level, err) return @@ -28,7 +28,7 @@ func testFileLevel(t *testing.T, fn string, level int) { defer golden.Close() // Read the file again, and push it through a pipe that compresses at the write end, and decompresses at the read end. - raw, err := os.Open(fn, os.O_RDONLY, 0444) + raw, err := os.Open(fn) if err != nil { t.Errorf("%s (level=%d): %v", fn, level, err) return |