Codebase list golang-github-vbauerster-mpb / c101017
drop decor/pool.go using sync.Pool to feed strconv.AppendFloat has negligible performance gain if at all. Vladimir Bauer 3 years ago
3 changed file(s) with 3 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
2222 }
2323 }
2424
25 p := bytesPool.Get().(*[]byte)
26 b := strconv.AppendFloat(*p, float64(s), 'f', prec, 64)
25 b := strconv.AppendFloat(make([]byte, 0, 32), float64(s), 'f', prec, 64)
2726 if st.Flag(' ') {
2827 b = append(b, ' ', '%')
2928 } else {
3332 if err != nil {
3433 panic(err)
3534 }
36 bytesPool.Put(p)
3735 }
3836
3937 // Percentage returns percentage decorator. It's a wrapper of NewPercentage.
+0
-10
decor/pool.go less more
0 package decor
1
2 import "sync"
3
4 var bytesPool = sync.Pool{
5 New: func() interface{} {
6 b := make([]byte, 0, 32)
7 return &b
8 },
9 }
4848 unit = _iTiB
4949 }
5050
51 p := bytesPool.Get().(*[]byte)
52 b := strconv.AppendFloat(*p, float64(self)/float64(unit), 'f', prec, 64)
51 b := strconv.AppendFloat(make([]byte, 0, 32), float64(self)/float64(unit), 'f', prec, 64)
5352 if st.Flag(' ') {
5453 b = append(b, ' ')
5554 }
5857 if err != nil {
5958 panic(err)
6059 }
61 bytesPool.Put(p)
6260 }
6361
6462 const (
102100 unit = _TB
103101 }
104102
105 p := bytesPool.Get().(*[]byte)
106 b := strconv.AppendFloat(*p, float64(self)/float64(unit), 'f', prec, 64)
103 b := strconv.AppendFloat(make([]byte, 0, 32), float64(self)/float64(unit), 'f', prec, 64)
107104 if st.Flag(' ') {
108105 b = append(b, ' ')
109106 }
112109 if err != nil {
113110 panic(err)
114111 }
115 bytesPool.Put(p)
116112 }