]> Cypherpunks repositories - gostls13.git/commitdiff
time: in Format give buffer an initial capacity
authorBobby Powers <bobbypowers@gmail.com>
Sat, 7 Apr 2012 00:51:32 +0000 (10:51 +1000)
committerRob Pike <r@golang.org>
Sat, 7 Apr 2012 00:51:32 +0000 (10:51 +1000)
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

src/pkg/time/format.go

index 98d4bb5c657ff63cfa6c46dc15b7e552683bf1e2..bb32bc84315746cc0f9064d62cb4ef007e5b309f 100644 (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 {