Debian Codegraph @

pkg/color/helpers_bench_test.go

raw
1 package color
2
3 import (
4 "testing"
5 )
6
7 // BenchmarkColorPrint benchmarks the Color.Print method for printing colored output.
8 func BenchmarkColorPrint(b *testing.B) {
9 cfg := &Config{
10 NoColor: false,
11 Output: nil,
12 Error: nil,
13 }
14
15 c := NewWithConfig(cfg, FgRed)
16
17 b.ResetTimer()
18
19 for b.Loop() {
20 _, _ = c.Print("test message")
21 }
22 }
23
24 // BenchmarkColorSprint benchmarks the Color.Sprint method for returning colored strings.
25 func BenchmarkColorSprint(b *testing.B) {
26 cfg := &Config{
27 NoColor: false,
28 Output: nil,
29 Error: nil,
30 }
31
32 c := NewWithConfig(cfg, FgRed)
33
34 b.ResetTimer()
35
36 for b.Loop() {
37 _ = c.Sprint("test message")
38 }
39 }
40
41 // BenchmarkColorSprintNoColor benchmarks the Color.Sprint method with NoColor enabled.
42 func BenchmarkColorSprintNoColor(b *testing.B) {
43 cfg := &Config{
44 NoColor: true,
45 Output: nil,
46 Error: nil,
47 }
48
49 c := NewWithConfig(cfg, FgRed)
50
51 b.ResetTimer()
52
53 for b.Loop() {
54 _ = c.Sprint("test message")
55 }
56 }