1
0
mirror of https://github.com/golang/go synced 2024-11-25 01:08:02 -07:00

exp/norm: fix benchmark bug

- don't use range over string to copy string bytes
- some code simplification

R=mpvl
CC=golang-dev
https://golang.org/cl/5144044
This commit is contained in:
Robert Griesemer 2011-09-26 18:23:21 -07:00
parent aeaa817140
commit 9c643bb3fa

View File

@ -485,19 +485,15 @@ func BenchmarkNormalizeAsciiNFKD(b *testing.B) {
func doTextBenchmark(b *testing.B, s string) {
b.StopTimer()
in := make([]byte, len(s))
for i := range s {
in[i] = s[i]
}
// Using copy(in, s) makes many tests much slower!?
b.SetBytes(int64(len(s)) * 4)
var buf = make([]byte, 2*len(in))
in := []byte(s)
var buf = make([]byte, 0, 2*len(in))
b.StartTimer()
for i := 0; i < b.N; i++ {
buf = NFC.Append(buf[0:0], in...)
buf = NFD.Append(buf[0:0], in...)
buf = NFKC.Append(buf[0:0], in...)
buf = NFKD.Append(buf[0:0], in...)
NFC.Append(buf, in...)
NFD.Append(buf, in...)
NFKC.Append(buf, in...)
NFKD.Append(buf, in...)
}
}