mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
strings: optimize Replace by using a strings.Builder
name old time/op new time/op delta ReplaceAll 162ns ±26% 134ns ±26% -17.44% (p=0.014 n=10+10) name old alloc/op new alloc/op delta ReplaceAll 32.0B ± 0% 16.0B ± 0% -50.00% (p=0.000 n=10+10) name old allocs/op new allocs/op delta ReplaceAll 2.00 ± 0% 1.00 ± 0% -50.00% (p=0.000 n=10+10) Change-Id: Ia8377141d3adb84c7bd94e511ac8f739915aeb40 Reviewed-on: https://go-review.googlesource.com/c/go/+/245197 Run-TryBot: Martin Möhrmann <moehrmann@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
parent
6f99b33c18
commit
51ac0f0f4c
2 changed files with 15 additions and 6 deletions
|
|
@ -1900,3 +1900,12 @@ func BenchmarkTrimSpace(b *testing.B) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
var stringSink string
|
||||
|
||||
func BenchmarkReplaceAll(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
stringSink = ReplaceAll("banana", "a", "<>")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue