1package anim
2
3import (
4 "testing"
5 "time"
6)
7
8func BenchmarkAnimationUpdate(b *testing.B) {
9 anim := New(30, "Loading test data")
10
11 b.ResetTimer()
12 for i := 0; i < b.N; i++ {
13 // Simulate character cycling update
14 _, _ = anim.Update(StepCharsMsg{id: anim.ID()})
15 }
16}
17
18func BenchmarkAnimationView(b *testing.B) {
19 anim := New(30, "Loading test data")
20
21 // Initialize with some cycling
22 for i := 0; i < 10; i++ {
23 anim.Update(StepCharsMsg{id: anim.ID()})
24 }
25
26 b.ResetTimer()
27 for i := 0; i < b.N; i++ {
28 _ = anim.View()
29 }
30}
31
32func BenchmarkRandomRune(b *testing.B) {
33 c := cyclingChar{}
34
35 b.ResetTimer()
36 for i := 0; i < b.N; i++ {
37 _ = c.randomRune()
38 }
39}
40
41func TestAnimationPerformance(t *testing.T) {
42 anim := New(30, "Performance test")
43
44 start := time.Now()
45 iterations := 1000
46
47 // Simulate rapid updates
48 for i := 0; i < iterations; i++ {
49 anim.Update(StepCharsMsg{id: anim.ID()})
50 _ = anim.View()
51 }
52
53 duration := time.Since(start)
54 avgPerUpdate := duration / time.Duration(iterations)
55
56 // Should complete 1000 updates in reasonable time
57 if avgPerUpdate > time.Millisecond {
58 t.Errorf("Animation update too slow: %v per update (should be < 1ms)", avgPerUpdate)
59 }
60
61 t.Logf("Animation performance: %v per update (%d updates in %v)",
62 avgPerUpdate, iterations, duration)
63}