TestInlineSliceAllocations shows that inline slices cause allocations
(t *testing.T)
| 25 | |
| 26 | // TestInlineSliceAllocations shows that inline slices cause allocations |
| 27 | func TestInlineSliceAllocations(t *testing.T) { |
| 28 | sm := NewConnStateMachine() |
| 29 | sm.Transition(StateIdle) |
| 30 | ctx := context.Background() |
| 31 | |
| 32 | // Test with inline slice - will allocate |
| 33 | allocs := testing.AllocsPerRun(100, func() { |
| 34 | _, _ = sm.AwaitAndTransition(ctx, []ConnState{StateIdle}, StateUnusable) |
| 35 | sm.Transition(StateIdle) |
| 36 | }) |
| 37 | |
| 38 | if allocs == 0 { |
| 39 | t.Logf("Inline slice had 0 allocations (compiler optimization)") |
| 40 | } else { |
| 41 | t.Logf("Inline slice caused %.2f allocations per run (expected)", allocs) |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | // BenchmarkAwaitAndTransition_PredefinedSlice benchmarks with predefined slice |
| 46 | func BenchmarkAwaitAndTransition_PredefinedSlice(b *testing.B) { |
nothing calls this directly
no test coverage detected