1//go:build stress23package ui45import (6 "fmt"7 "testing"89 tea "charm.land/bubbletea/v2"1011 "src.rest/cat/012/internal/stress"12)1314// BenchmarkSourceScroll scrolls a linked source of ten million rows15// (stress.SalesParquet) through to its frames: Page Down and Up within16// the rows read, halfway down, as scrolling is between pages; and17// jumping to rows all over the source, as dragging the scrollbar does,18// reading the pages each jump shows (run to the end here, in the19// background on the screen) before the frame that shows them. The row20// numbers and the scrollbar are over every row, whatever the grid's.21func BenchmarkSourceScroll(b *testing.B) {22 path, err := stress.SalesParquet(stress.GeneratedDir(b.TempDir()), 10_000_000)23 if err != nil {24 b.Fatal(err)25 }26 defer stress.BenchLock(b)()27 cases := []struct {28 name string29 keys []tea.KeyPressMsg30 read bool31 }{32 {"pgdown", []tea.KeyPressMsg{{Code: tea.KeyPgDown}, {Code: tea.KeyPgUp}}, false},33 {"jump", nil, true},34 }35 for _, c := range cases {36 for _, sz := range termSizes[:2] {37 b.Run(fmt.Sprintf("%s/%dx%d", c.name, sz.w, sz.h), func(b *testing.B) {38 m := sourceModel(path, sz.w, sz.h)39 m.srcView().MoveTo(5_000_000, 2)40 for _, k := range c.keys {41 m.Update(k)42 settleSources(m)43 }44 t := newFakeTerm(sz.w, sz.h)45 i := 046 for b.Loop() {47 if c.read {48 m.srcView().MoveTo(int64(i)*1_234_567%10_000_000, 2)49 settleSources(m)50 } else {51 m.Update(c.keys[i%2])52 }53 t.frame(m)54 i++55 }56 })57 }58 }59}