1
0
mirror of https://github.com/golang/go synced 2024-11-22 20:14:40 -07:00

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
This commit is contained in:
Bobby Powers 2012-04-07 10:51:32 +10:00 committed by Rob Pike
parent f27348776f
commit c9529e02c1

View File

@ -367,7 +367,7 @@ func (t Time) Format(layout string) string {
hour int = -1
min int
sec int
b buffer
b buffer = make([]byte, 0, len(layout))
)
// Each iteration generates one std value.
for {