go/src/encoding/csv
Justin Nuß 2db58f8f2d encoding/csv: Preallocate records slice
Currently parseRecord will always start with a nil
slice and then resize the slice on append. For input
with a fixed number of fields per record we can preallocate
the slice to avoid having to resize the slice.

This change implements this optimization by using
FieldsPerRecord as capacity if it's > 0 and also adds a
benchmark to better show the differences.

benchmark         old ns/op     new ns/op     delta
BenchmarkRead     19741         17909         -9.28%

benchmark         old allocs     new allocs     delta
BenchmarkRead     59             41             -30.51%

benchmark         old bytes     new bytes     delta
BenchmarkRead     6276          5844          -6.88%

Change-Id: I7c2abc9c80a23571369bcfcc99a8ffc474eae7ab
Reviewed-on: https://go-review.googlesource.com/8880
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-04-26 16:28:51 +00:00
..
reader.go encoding/csv: Preallocate records slice 2015-04-26 16:28:51 +00:00
reader_test.go encoding/csv: Preallocate records slice 2015-04-26 16:28:51 +00:00
writer.go all: use "reports whether" in place of "returns true if(f)" 2015-03-18 15:14:06 +00:00
writer_test.go encoding/csv: for Postgres, unquote empty strings, quote \. 2014-10-23 23:44:47 -04:00