| 1 | package color |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | // Benchmark_boolPtr benchmarks the boolPtr function for creating boolean pointers. |
| 9 | func Benchmark_boolPtr(b *testing.B) { |
| 10 | for b.Loop() { |
| 11 | _ = boolPtr(true) |
| 12 | _ = boolPtr(false) |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | // Benchmark_sprintln benchmarks the sprintln function for joining arguments with spaces. |
| 17 | func Benchmark_sprintln(b *testing.B) { |
| 18 | args := []any{"hello", "world", 123} |
| 19 | |
| 20 | for b.Loop() { |
| 21 | _ = sprintln(args...) |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | // Benchmark_noColorIsSet benchmarks the noColorIsSet function for checking NO_COLOR environment variable. |
| 26 | func Benchmark_noColorIsSet(b *testing.B) { |
| 27 | // Save original environment |
| 28 | originalEnv := os.Getenv("NO_COLOR") |
| 29 | |
| 30 | os.Unsetenv("NO_COLOR") |
| 31 | b.Cleanup(func() { |
| 32 | if originalEnv == "" { |
| 33 | os.Unsetenv("NO_COLOR") |
| 34 | } else { |
| 35 | os.Setenv("NO_COLOR", originalEnv) |
| 36 | } |
| 37 | }) |
| 38 | |
| 39 | for b.Loop() { |
| 40 | _ = noColorIsSet() |
| 41 | } |
| 42 | } |