File: cuuAndEd_construction_bench_test.go

package info (click to toggle)
golang-github-vbauerster-mpb 8.8.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,044 kB
  • sloc: sh: 7; makefile: 3
file content (45 lines) | stat: -rw-r--r-- 856 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package cwriter

import (
	"bytes"
	"fmt"
	"io"
	"strconv"
	"testing"
)

var (
	out   = io.Discard
	lines = 99
)

func BenchmarkWithFprintf(b *testing.B) {
	verb := fmt.Sprintf("%s%%d%s", escOpen, cuuAndEd)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		fmt.Fprintf(out, verb, lines)
	}
}

func BenchmarkWithJoin(b *testing.B) {
	bCuuAndEd := [][]byte{[]byte(escOpen), []byte(cuuAndEd)}
	for i := 0; i < b.N; i++ {
		_, _ = out.Write(bytes.Join(bCuuAndEd, []byte(strconv.Itoa(lines))))
	}
}

func BenchmarkWithAppend(b *testing.B) {
	escOpen := []byte(escOpen)
	cuuAndEd := []byte(cuuAndEd)
	for i := 0; i < b.N; i++ {
		_, _ = out.Write(append(strconv.AppendInt(escOpen, int64(lines), 10), cuuAndEd...))
	}
}

func BenchmarkWithCurrentImpl(b *testing.B) {
	w := New(out)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		_ = w.ew.ansiCuuAndEd(out, lines)
	}
}