// The c == hi case is a special case.
suffix [1 << maxWidth]uint8
prefix [1 << maxWidth]uint16
+ // buf is a scratch buffer for reconstituting the bytes that a code expands to.
+ // Code suffixes are written right-to-left from the end of the buffer.
+ buf [1 << maxWidth]byte
)
// Loop over the code stream, converting codes into decompressed bytes.
case code == eof:
return w.Flush()
case code <= hi:
- // buf is a scratch buffer for reconstituting the bytes that a code expands to.
- // Code suffixes are written right-to-left from the end of the buffer.
- var buf [1 << maxWidth]byte
c, i := code, len(buf)-1
if code == hi {
// code == hi is a special case which expands to the last expansion
import (
"bytes"
"io"
+ "io/ioutil"
"os"
"strconv"
"strings"
}
}
}
+
+type devNull struct{}
+
+func (devNull) Write(p []byte) (int, os.Error) {
+ return len(p), nil
+}
+
+func BenchmarkDecoder(b *testing.B) {
+ b.StopTimer()
+ buf0, _ := ioutil.ReadFile("../testdata/e.txt")
+ compressed := bytes.NewBuffer(nil)
+ w := NewWriter(compressed, LSB, 8)
+ io.Copy(w, bytes.NewBuffer(buf0))
+ w.Close()
+ buf1 := compressed.Bytes()
+ b.StartTimer()
+ for i := 0; i < b.N; i++ {
+ io.Copy(devNull{}, NewReader(bytes.NewBuffer(buf1), LSB, 8))
+ }
+}
}
}
}
+
+func BenchmarkEncoder(b *testing.B) {
+ b.StopTimer()
+ buf, _ := ioutil.ReadFile("../testdata/e.txt")
+ b.StartTimer()
+ for i := 0; i < b.N; i++ {
+ w := NewWriter(devNull{}, LSB, 8)
+ w.Write(buf)
+ w.Close()
+ }
+}