• Brad Fitzpatrick's avatar
    strings: add Builder benchmarks comparing bytes.Buffer and strings.Builder · b1accced
    Brad Fitzpatrick authored
    Despite the existing test that locks in the allocation behavior, people
    really want a benchmark. So:
    
    BenchmarkBuildString_Builder/1Write_NoGrow-4    20000000  60.4 ns/op   48 B/op  1 allocs/op
    BenchmarkBuildString_Builder/3Write_NoGrow-4    10000000   230 ns/op  336 B/op  3 allocs/op
    BenchmarkBuildString_Builder/3Write_Grow-4      20000000   102 ns/op  112 B/op  1 allocs/op
    BenchmarkBuildString_ByteBuffer/1Write_NoGrow-4 10000000   125 ns/op  160 B/op  2 allocs/op
    BenchmarkBuildString_ByteBuffer/3Write_NoGrow-4  5000000   339 ns/op  400 B/op  3 allocs/op
    BenchmarkBuildString_ByteBuffer/3Write_Grow-4    5000000   316 ns/op  336 B/op  3 allocs/op
    
    I don't think these allocate-as-fast-as-you-can benchmarks are very
    interesting because they're effectively just GC benchmarks, but sure.
    If one wants to see that there's 1 fewer allocation, there it is. The
    ns/op and B/op numbers will change as the built string size changes.
    
    Updates #18990
    
    Change-Id: Ifccf535bd396217434a0e6989e195105f90132ae
    Reviewed-on: https://go-review.googlesource.com/96980
    Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    Reviewed-by: 's avatarAlan Donovan <adonovan@google.com>
    b1accced
Name
Last commit
Last update
..
builder.go Loading commit data...
builder_test.go Loading commit data...
compare.go Loading commit data...
compare_test.go Loading commit data...
example_test.go Loading commit data...
export_test.go Loading commit data...
reader.go Loading commit data...
reader_test.go Loading commit data...
replace.go Loading commit data...
replace_test.go Loading commit data...
search.go Loading commit data...
search_test.go Loading commit data...
strings.go Loading commit data...
strings.s Loading commit data...
strings_amd64.go Loading commit data...
strings_decl.go Loading commit data...
strings_generic.go Loading commit data...
strings_s390x.go Loading commit data...
strings_test.go Loading commit data...