mirror of
https://github.com/golang/go
synced 2024-11-25 03:27:58 -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:
parent
aeaa817140
commit
9c643bb3fa
@ -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...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user