Commit 9c643bb3 authored by Robert Griesemer's avatar Robert Griesemer

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
parent aeaa8171
...@@ -485,19 +485,15 @@ func BenchmarkNormalizeAsciiNFKD(b *testing.B) { ...@@ -485,19 +485,15 @@ func BenchmarkNormalizeAsciiNFKD(b *testing.B) {
func doTextBenchmark(b *testing.B, s string) { func doTextBenchmark(b *testing.B, s string) {
b.StopTimer() 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) 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() b.StartTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
buf = NFC.Append(buf[0:0], in...) NFC.Append(buf, in...)
buf = NFD.Append(buf[0:0], in...) NFD.Append(buf, in...)
buf = NFKC.Append(buf[0:0], in...) NFKC.Append(buf, in...)
buf = NFKD.Append(buf[0:0], in...) NFKD.Append(buf, in...)
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment