render_bench_test.go

 1package tui
 2
 3import (
 4	"strings"
 5	"testing"
 6	"time"
 7
 8	"github.com/floatpane/matcha/config"
 9	"github.com/floatpane/matcha/fetcher"
10)
11
12func BenchmarkLogPanelView(b *testing.B) {
13	logger := &snapshotLogger{}
14	for i := 0; i < 10; i++ {
15		logger.Write([]byte("benchmark log line " + strings.Repeat("x", 40) + "\n"))
16	}
17	panel := NewLogPanel(logger)
18	panel.SetSize(80, 12)
19
20	b.ReportAllocs()
21	for i := 0; i < b.N; i++ {
22		_ = panel.View()
23	}
24}
25
26func BenchmarkSearchOverlayView(b *testing.B) {
27	overlay := NewSearchOverlay(80, 24)
28	emails := make([]fetcher.Email, 10)
29	for i := range emails {
30		emails[i] = fetcher.Email{
31			UID:     uint32(i),
32			From:    "sender@example.com",
33			Subject: "Benchmark email subject",
34			Date:    time.Now(),
35		}
36	}
37	overlay.results = emails
38	overlay.done = true
39
40	b.ReportAllocs()
41	for i := 0; i < b.N; i++ {
42		_ = overlay.View()
43	}
44}
45
46func BenchmarkInboxConstruction(b *testing.B) {
47	accounts := []config.Account{{ID: "a", Email: "a@example.com"}}
48	emails := make([]fetcher.Email, 500)
49	for i := range emails {
50		emails[i] = fetcher.Email{
51			UID:       uint32(i),
52			From:      "bench@example.com",
53			Subject:   "Subject line " + strings.Repeat("y", 20),
54			Date:      time.Now().Add(-time.Duration(i) * time.Minute),
55			AccountID: "a",
56		}
57	}
58	b.ReportAllocs()
59	for i := 0; i < b.N; i++ {
60		_ = NewInbox(emails, accounts)
61	}
62}