-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbenchmark_alloc_test.go
More file actions
62 lines (53 loc) · 1.58 KB
/
benchmark_alloc_test.go
File metadata and controls
62 lines (53 loc) · 1.58 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
package mtlog
import (
"fmt"
"testing"
"github.com/willibrandon/mtlog/core"
"github.com/willibrandon/mtlog/internal/parser"
)
// Let's break down where allocations happen
func TestAllocationBreakdown(t *testing.T) {
// Test 1: Parse template
t.Run("ParseTemplate", func(t *testing.T) {
allocs := testing.AllocsPerRun(100, func() {
_, err := parser.Parse("This is a simple log message")
if err != nil {
panic(fmt.Sprintf("Failed to parse template: %v", err))
}
})
t.Logf("Parse template allocations: %.1f", allocs)
})
// Test 2: Create LogEvent
t.Run("CreateLogEvent", func(t *testing.T) {
allocs := testing.AllocsPerRun(100, func() {
_ = &core.LogEvent{
Properties: make(map[string]any),
}
})
t.Logf("Create LogEvent allocations: %.1f", allocs)
})
// Test 3: Extract properties (empty)
t.Run("ExtractProperties", func(t *testing.T) {
logger := New()
tmpl, _ := parser.Parse("This is a simple log message")
allocs := testing.AllocsPerRun(100, func() {
logger.extractProperties(tmpl, nil)
})
t.Logf("Extract properties allocations: %.1f", allocs)
})
// Test 4: Full logging flow
t.Run("FullLoggingFlow", func(t *testing.T) {
logger := New(WithSink(&discardSink{}))
allocs := testing.AllocsPerRun(100, func() {
logger.Information("This is a simple log message")
})
t.Logf("Full logging flow allocations: %.1f", allocs)
})
// Test 5: Just the map creation
t.Run("MapCreation", func(t *testing.T) {
allocs := testing.AllocsPerRun(100, func() {
_ = make(map[string]any)
})
t.Logf("Map creation allocations: %.1f", allocs)
})
}