-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
95 lines (81 loc) · 2.23 KB
/
main.go
File metadata and controls
95 lines (81 loc) · 2.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"fmt"
"strings"
"time"
"github.com/BaseMax/go-benchclock"
)
func main() {
fmt.Println("=== Go BenchClock - Advanced Benchmarking Utility ===")
fmt.Println()
// Example 1: Simple string concatenation benchmark
benchmark1 := benchclock.New("String Concatenation", func() {
result := ""
for i := 0; i < 100; i++ {
result += "x"
}
})
// Example 2: String builder benchmark
benchmark2 := benchclock.New("String Builder", func() {
var builder strings.Builder
for i := 0; i < 100; i++ {
builder.WriteString("x")
}
_ = builder.String()
})
// Example 3: Map operations benchmark
benchmark3 := benchclock.New("Map Operations", func() {
m := make(map[int]int)
for i := 0; i < 100; i++ {
m[i] = i * 2
}
for i := 0; i < 100; i++ {
_ = m[i]
}
})
// Custom configuration for more detailed analysis
customConfig := &benchclock.Config{
MinIterations: 200,
MaxIterations: 10000,
MinDuration: 2 * time.Second,
WarmupIterations: 20,
CorrectClockDrift: true,
DetectCPUScaling: true,
}
benchmark1.WithConfig(customConfig)
benchmark2.WithConfig(customConfig)
benchmark3.WithConfig(customConfig)
// Run benchmarks
fmt.Println("Running benchmarks (this may take a few seconds)...")
fmt.Println()
results, err := benchclock.RunMultiple([]*benchclock.Benchmark{
benchmark1,
benchmark2,
benchmark3,
})
if err != nil {
fmt.Printf("Error running benchmarks: %v\n", err)
return
}
// Display results
for i, result := range results {
fmt.Printf("--- Result %d ---\n", i+1)
fmt.Println(result.String())
fmt.Println()
}
// Compare benchmarks
if len(results) >= 2 {
fmt.Println("=== Comparisons ===")
fmt.Println(benchclock.Compare(results[0], results[1]))
fmt.Println(benchclock.Compare(results[0], results[2]))
fmt.Println(benchclock.Compare(results[1], results[2]))
}
fmt.Println("\n=== Summary ===")
fmt.Println("All benchmarks completed successfully!")
fmt.Println("Statistical analysis includes:")
fmt.Println(" ✓ Clock drift correction")
fmt.Println(" ✓ CPU scaling detection")
fmt.Println(" ✓ Warm-up bias elimination")
fmt.Println(" ✓ 95% and 99% confidence intervals")
fmt.Println(" ✓ Variance and standard deviation metrics")
}