- commit
- c0e3923663f7f260444e21041b0f89d60fd24a1e
- parent
- 6fef7ff87932957efb9097a34cc96f84227b5674
- author
- Dami <dami.etoile@gmail.com>
| A | internal/ | 75 | ++++++++++++++++++++++++++++++ |
@@ -0,0 +1,75 @@
1+//go:build stress2+3+// Stress benchmarks of the hot paths under every edit and every frame:4+// parsing formulas, recognizing typed values, and rendering numbers5+// through their formats.6+package sheet_test7+8+import (9+ "testing"10+11+ "github.com/FelineStateMachine/012/internal/sheet"12+)13+14+var parseInputs = []string{15+ "=A1+B2*3",16+ "=SUM($A$1:A100)/COUNT(A1:A100)",17+ `=IF(AND(B2>0,C2<>""),VLOOKUP(B2,Data!A1:D500,3,FALSE),"none")`,18+ `=TEXT(DATE(2026,9,26),"yyyy-mm-dd")&" "&'Q3 plan'!B7`,19+ "=-2^2+1.5E-3*(A1..B3)%",20+}21+22+// BenchmarkParse lexes and parses a mix of formulas.23+func BenchmarkParse(b *testing.B) {24+ for b.Loop() {25+ for _, src := range parseInputs {26+ if _, err := sheet.Parse(src); err != nil {27+ b.Fatal(err)28+ }29+ }30+ }31+}32+33+// BenchmarkParseValue recognizes typed numbers, currency, dates and times.34+func BenchmarkParseValue(b *testing.B) {35+ inputs := []string{"1234.5", "$1,200.00", "12%", "9/26/2026", "2026-09-26", "Sep 26, 2026", "2:30 PM", "9/26/2026 14:30:05", "hello"}36+ for b.Loop() {37+ for _, s := range inputs {38+ sheet.ParseValue(s)39+ }40+ }41+}42+43+// BenchmarkFormatPattern renders numbers and dates through patterns, as44+// every visible formatted cell does each frame.45+func BenchmarkFormatPattern(b *testing.B) {46+ cases := []struct {47+ v float6448+ pat string49+ }{50+ {1234567.891, "#,##0.00"},51+ {-0.1234, "0.0%"},52+ {12345.678, "0.00E+00"},53+ {-1234.5, "$#,##0;($#,##0)"},54+ {46291.604, "m/d/yyyy h:mm:ss am/pm"},55+ {1.5, "[h]:mm:ss.00"},56+ {46291, "dddd, mmmm d, yyyy"},57+ }58+ for b.Loop() {59+ for _, c := range cases {60+ sheet.FormatPattern(c.v, c.pat)61+ }62+ }63+}64+65+// BenchmarkDisplay renders values the way the grid does, per visible cell.66+func BenchmarkDisplay(b *testing.B) {67+ num := sheet.Value{Kind: sheet.Number, Num: 1234.5678}68+ formats := []sheet.Format{{}, sheet.Preset(sheet.FmtNumber), sheet.Preset(sheet.FmtCurrency),69+ sheet.Preset(sheet.FmtAccounting), sheet.Preset(sheet.FmtDate), sheet.Preset(sheet.FmtPercent)}70+ for b.Loop() {71+ for _, f := range formats {72+ sheet.Display(num, f, 12)73+ }74+ }75+}