]> Cypherpunks repositories - gostls13.git/commit
archive/tar: optimize formatPAXRecord() call
authorAgniva De Sarker <agnivade@yahoo.co.in>
Fri, 11 Aug 2017 19:23:45 +0000 (00:53 +0530)
committerJoe Tsai <thebrokentoaster@gmail.com>
Sat, 12 Aug 2017 04:52:27 +0000 (04:52 +0000)
commit23cd87eb0a2d49a3208824feaf34d8b852da422f
treef5057d409a01a517b54bfdce1916d8587d7fba17
parent0d1a8f6e12770db8982ed23bc67228237671085d
archive/tar: optimize formatPAXRecord() call

By replacing fmt.Sprintf with a simple string concat, we see
pretty good improvements across the board on time and memory.

name             old time/op    new time/op    delta
FormatPAXRecord     683ns ± 2%     210ns ± 5%  -69.22%  (p=0.000 n=10+10)

name             old alloc/op   new alloc/op   delta
FormatPAXRecord      112B ± 0%       32B ± 0%  -71.43%  (p=0.000 n=10+10)

name             old allocs/op  new allocs/op  delta
FormatPAXRecord      8.00 ± 0%      2.00 ± 0%  -75.00%  (p=0.000 n=10+10)

Ran with - -cpu=1 -count=10 on an AMD64 i5-5200U CPU @ 2.20GHz

Using the following benchmark:
func BenchmarkFormatPAXRecord(b *testing.B) {
  for n := 0; n < b.N; n++ {
    formatPAXRecord("foo", "bar")
  }
}

Change-Id: I828ddbafad2e5d937f0cf5f777b512638344acfc
Reviewed-on: https://go-review.googlesource.com/55210
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
src/archive/tar/strconv.go