Skip to content

Commit

Permalink
Add a benchmark for scrolling through a large filtered table (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evertras authored Mar 17, 2023
1 parent 2be15e5 commit 434f968
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions table/filter_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package table

import (
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -281,3 +282,34 @@ func TestFilterWithSetValue(t *testing.T) {
filteredRows = model.getFilteredRows(rows)
assert.Len(t, filteredRows, 3)
}

func BenchmarkFilteredScrolling(b *testing.B) {
// Scrolling through a filtered table with many rows should be quick
// https://github.com/Evertras/bubble-table/issues/135
const rowCount = 40000
columns := []Column{NewColumn("title", "title", 10).WithFiltered(true)}
rows := make([]Row, rowCount)

for i := 0; i < rowCount; i++ {
rows[i] = NewRow(RowData{
"title": fmt.Sprintf("%d", i),
})
}

model := New(columns).WithRows(rows).Filtered(true)
model = model.WithFilterInputValue("1")

hitKey := func(key rune) {
model, _ = model.Update(
tea.KeyMsg{
Type: tea.KeyRunes,
Runes: []rune{key},
})
}

b.ResetTimer()

for i := 0; i < b.N; i++ {
hitKey('j')
}
}

0 comments on commit 434f968

Please sign in to comment.