Skip to content

Commit c9529e0

Browse files
bpowersrobpike
authored andcommitted
time: in Format give buffer an initial capacity
I have a small web server that simply sets several cookies along with an expires header, and then returns. In the cpuprofile for a 200k request benchmark, time.Time.Format() was showing up as 8.3% of cpu usage. Giving the buffer an inital capacity to avoid reallocs on append drops it down to 7.6%. R=golang-dev, r CC=golang-dev https://golang.org/cl/5992058
1 parent f273487 commit c9529e0

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/pkg/time/format.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ func (t Time) Format(layout string) string {
367367
hour int = -1
368368
min int
369369
sec int
370-
b buffer
370+
b buffer = make([]byte, 0, len(layout))
371371
)
372372
// Each iteration generates one std value.
373373
for {

0 commit comments

Comments
 (0)