Skip to content

Commit

Permalink
cmd/pack: buffer writes in TestLargeDefs
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ality authored and robpike committed May 16, 2014
1 parent 74fe67f commit c6aa2e5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/cmd/pack/pack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package main

import (
"bufio"
"bytes"
"fmt"
"io"
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit c6aa2e5

Please sign in to comment.