aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/pack
diff options
context:
space:
mode:
authorAnthony Martin <ality@pbrane.org>2014-05-15 20:12:06 -0700
committerRob Pike <r@golang.org>2014-05-15 20:12:06 -0700
commitc6aa2e5ac8097f9491a407c3bb2385159d9aed32 (patch)
tree7fb5941023f324f10fcfde4a5a25a989112c92e3 /src/cmd/pack
parent74fe67f22e41f06ab93fc5123964f144040191aa (diff)
downloadgo-c6aa2e5ac8097f9491a407c3bb2385159d9aed32.tar.gz
go-c6aa2e5ac8097f9491a407c3bb2385159d9aed32.zip
cmd/pack: buffer writes in TestLargeDefs
TestLargeDefs was issuing over one million small writes to create a 7MB file (large.go). This is quite slow on Plan 9 since our disk file systems aren't very fast and they're usually accessed over the network. Buffering the writes makes the test about six times faster. Even on Linux, it's about 1.5 times faster. Here are the results on a slow Plan 9 machine: Before: % ./pack.test -test.v -test.run TestLargeDefs === RUN TestLargeDefs --- PASS: TestLargeDefs (125.11 seconds) PASS After: % ./pack.test -test.v -test.run TestLargeDefs === RUN TestLargeDefs --- PASS: TestLargeDefs (20.835 seconds) PASS LGTM=iant R=golang-codereviews, iant CC=golang-codereviews https://golang.org/cl/95040044
Diffstat (limited to 'src/cmd/pack')
-rw-r--r--src/cmd/pack/pack_test.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/cmd/pack/pack_test.go b/src/cmd/pack/pack_test.go
index 8ecca98e63..e634c86f76 100644
--- a/src/cmd/pack/pack_test.go
+++ b/src/cmd/pack/pack_test.go
@@ -5,6 +5,7 @@
package main
import (
+ "bufio"
"bytes"
"fmt"
"io"
@@ -223,9 +224,10 @@ func TestLargeDefs(t *testing.T) {
if err != nil {
t.Fatal(err)
}
+ b := bufio.NewWriter(f)
printf := func(format string, args ...interface{}) {
- _, err := fmt.Fprintf(f, format, args...)
+ _, err := fmt.Fprintf(b, format, args...)
if err != nil {
t.Fatalf("Writing to %s: %v", large, err)
}
@@ -240,6 +242,9 @@ func TestLargeDefs(t *testing.T) {
printf("\"`\n")
}
printf("}\n")
+ if err = b.Flush(); err != nil {
+ t.Fatal(err)
+ }
if err = f.Close(); err != nil {
t.Fatal(err)
}