-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathperformance_test.go
More file actions
65 lines (55 loc) · 1.23 KB
/
performance_test.go
File metadata and controls
65 lines (55 loc) · 1.23 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package color
import (
"fmt"
"strconv"
"testing"
)
func BenchmarkRenderCode_SingleString(b *testing.B) {
for i := 0; i < b.N; i++ {
RenderCode("32", "Hello World")
}
}
func BenchmarkRenderCode_TwoStrings(b *testing.B) {
for i := 0; i < b.N; i++ {
RenderCode("32", "Hello", "World")
}
}
func BenchmarkRenderCode_UserPattern(b *testing.B) {
for i := 0; i < b.N; i++ {
RenderCode("32", strconv.Itoa(i)+". ", "test")
}
}
func BenchmarkColorRender_SingleString(b *testing.B) {
yellow := FgGreen.Render
for i := 0; i < b.N; i++ {
yellow("Hello World")
}
}
func BenchmarkColorRender_TwoStrings(b *testing.B) {
yellow := FgGreen.Render
for i := 0; i < b.N; i++ {
yellow("Hello", "World")
}
}
func BenchmarkColorRender_UserPattern(b *testing.B) {
yellow := FgGreen.Render
for i := 0; i < b.N; i++ {
yellow(strconv.Itoa(i)+". ", "test")
}
}
// Baseline comparisons
func BenchmarkFmtSprint_SingleString(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = fmt.Sprint("Hello World")
}
}
func BenchmarkFmtSprint_TwoStrings(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = fmt.Sprint("Hello", "World")
}
}
func BenchmarkFmtSprint_UserPattern(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = fmt.Sprint(strconv.Itoa(i)+". ", "test")
}
}