Codebase list golang-github-vbauerster-mpb / fbf394d
confirm that ansiCuuAndEd doesn't allocate go test -run XXX -bench=. -benchmem Vladimir Bauer 3 years ago
1 changed file(s) with 15 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
77 "testing"
88 )
99
10 var (
11 out = ioutil.Discard
12 lines = 99
13 )
14
1015 func BenchmarkWithFprintf(b *testing.B) {
11 cuuAndEd := "\x1b[%dA\x1b[J"
16 verb := fmt.Sprintf("%s%%d%s", escOpen, cuuAndEd)
17 b.ResetTimer()
1218 for i := 0; i < b.N; i++ {
13 fmt.Fprintf(ioutil.Discard, cuuAndEd, 4)
19 fmt.Fprintf(out, verb, lines)
1420 }
1521 }
1622
1723 func BenchmarkWithJoin(b *testing.B) {
18 bCuuAndEd := [][]byte{[]byte("\x1b["), []byte("A\x1b[J")}
24 bCuuAndEd := [][]byte{[]byte(escOpen), []byte(cuuAndEd)}
1925 for i := 0; i < b.N; i++ {
20 _, _ = ioutil.Discard.Write(bytes.Join(bCuuAndEd, []byte(strconv.Itoa(4))))
26 _, _ = out.Write(bytes.Join(bCuuAndEd, []byte(strconv.Itoa(lines))))
2127 }
2228 }
2329
2430 func BenchmarkWithAppend(b *testing.B) {
25 escOpen := []byte("\x1b[")
26 cuuAndEd := []byte("A\x1b[J")
31 escOpen := []byte(escOpen)
32 cuuAndEd := []byte(cuuAndEd)
2733 for i := 0; i < b.N; i++ {
28 _, _ = ioutil.Discard.Write(append(strconv.AppendInt(escOpen, 4, 10), cuuAndEd...))
34 _, _ = out.Write(append(strconv.AppendInt(escOpen, int64(lines), 10), cuuAndEd...))
2935 }
3036 }
3137
32 func BenchmarkWithCopy(b *testing.B) {
33 w := New(ioutil.Discard)
34 w.lines = 4
38 func BenchmarkWithCurrentImpl(b *testing.B) {
3539 for i := 0; i < b.N; i++ {
36 _ = w.ansiCuuAndEd()
40 _ = ansiCuuAndEd(out, lines)
3741 }
3842 }