diff options
| author | Agniva De Sarker <agnivade@yahoo.co.in> | 2017-09-27 23:30:43 +0530 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2017-09-27 19:52:55 +0000 |
| commit | ecff94311d793dcb4c590690473aa1421f549f03 (patch) | |
| tree | ccc5b379cd5f98d384df979b010646a8a859f4c0 /src/database/sql | |
| parent | d94078f04017533a89661514035d565261240ebb (diff) | |
| download | go-ecff94311d793dcb4c590690473aa1421f549f03.tar.xz | |
cmd/cgo: simplify a call to strip spaces
Combined the Split and Join call with a Replace. This simplifies
the code as well as makes it fast.
Micro-benchmarks show good improvements -
func BenchmarkJoinSplit(b *testing.B) {
for n := 0; n < b.N; n++ {
strings.Join(strings.Split("this string has some spaces", " "), "")
}
}
func BenchmarkReplace(b *testing.B) {
for n := 0; n < b.N; n++ {
strings.Replace("this string has some spaces", " ", "", -1)
}
}
name old time/op new time/op delta
JoinSplit-4 308ns ± 2% 192ns ± 4% -37.60% (p=0.008 n=5+5)
name old alloc/op new alloc/op delta
JoinSplit-4 144B ± 0% 64B ± 0% -55.56% (p=0.008 n=5+5)
name old allocs/op new allocs/op delta
JoinSplit-4 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.008 n=5+5)
Change-Id: I1dc32105ae7a0be5a43ab0bedde992cefbed5d7d
Reviewed-on: https://go-review.googlesource.com/66590
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/database/sql')
0 files changed, 0 insertions, 0 deletions
