cat / 012
clone

a spreadsheet for the terminal: lotus 1-2-3 looks, google sheets keys and formulas, one go binary

Add stress benchmarks of chart drawing, as text and as images

Dami committed fe81beb
commit
fe81beba7385737045d8436dd5dd4e6fdb1b4ef5
parent
6ae343554e1df0ac291f2c4d14267551d79aca71
author
Dami <dami.etoile@gmail.com>
1 file changed, +76 -0
Ainternal/chart/stress_test.go76++++++++++++++++++++++++++++++
A internal/chart/stress_test.go +76 -0
@@ -0,0 +1,76 @@
1+//go:build stress2+3+// Stress benchmarks of chart drawing: every chart type as text and as an4+// image, at a typical size and a large one, over a few categories and5+// over a full column of them (only what fits is drawn). Only built with6+// -tags stress (see `make stress` and docs/limits.md).7+package chart8+9+import (10+ "fmt"11+ "image/color"12+ "math"13+ "strconv"14+ "testing"15+16+ "github.com/FelineStateMachine/012/internal/sheet"17+)18+19+// stressData is n categories of three series of wavy values.20+func stressData(n int) sheet.ChartData {21+ d := sheet.ChartData{Categories: make([]string, n)}22+ for i := range n {23+ d.Categories[i] = "Cat " + strconv.Itoa(i+1)24+ }25+ for j := range 3 {26+ s := sheet.ChartSeries{Name: "Series " + strconv.Itoa(j+1), Values: make([]float64, n)}27+ for i := range n {28+ s.Values[i] = 1000*math.Sin(float64(i+j)/7) + 200*float64(j)29+ }30+ d.Series = append(d.Series, s)31+ }32+ return d33+}34+35+var stressTypes = []struct {36+ name string37+ t sheet.ChartType38+}{39+ {"column", sheet.ChartColumn},40+ {"bar", sheet.ChartBar},41+ {"line", sheet.ChartLine},42+ {"pie", sheet.ChartPie},43+}44+45+var stressSizes = []struct{ w, h int }{{24, 10}, {120, 40}}46+47+// BenchmarkDraw is a chart drawn as text, as every frame showing it does.48+func BenchmarkDraw(b *testing.B) {49+ for _, n := range []int{12, sheet.MaxRows} {50+ d := stressData(n)51+ for _, ct := range stressTypes {52+ for _, sz := range stressSizes {53+ b.Run(fmt.Sprintf("%s/%dcats/%dx%d", ct.name, n, sz.w, sz.h), func(b *testing.B) {54+ for b.Loop() {55+ Draw(ct.t, d, sz.w, sz.h, Options{})56+ }57+ })58+ }59+ }60+ }61+}62+63+// BenchmarkImage is a chart's plot drawn as a kitty image.64+func BenchmarkImage(b *testing.B) {65+ pal := Palette{Grid: color.RGBA{128, 128, 128, 80}}66+ d := stressData(12)67+ for _, ct := range stressTypes {68+ for _, sz := range stressSizes {69+ b.Run(fmt.Sprintf("%s/%dx%d", ct.name, sz.w, sz.h), func(b *testing.B) {70+ for b.Loop() {71+ Image(ct.t, d, sz.w, sz.h, Options{CellW: 10, CellH: 20}, pal)72+ }73+ })74+ }75+ }76+}