1//go:build stress23package sheet_test45import (6 "runtime"7 "testing"89 "src.rest/cat/012/internal/sheet"10 "src.rest/cat/012/internal/stress"11)1213// BenchmarkMemoryDerived is the heap a derived cell holds: the cells a14// formula spills (SEQUENCE over 8192 x 64, the array the anchor keeps15// to compare with the next one reported apart) and a pivot's results16// (a row per id of a 8191-row table, with a SUM and a COUNTA).17func BenchmarkMemoryDerived(b *testing.B) {18 b.Run("spilled-8192x64", func(b *testing.B) {19 for b.Loop() {20 before := heap()21 s := sheet.New()22 if err := s.Set(sheet.Addr{}, "=SEQUENCE(8192, 64)"); err != nil {23 b.Fatal(err)24 }25 after := heap()26 n := float64(s.Len())27 const valueBytes = 32 // a Value in the array the anchor keeps28 b.ReportMetric(float64(after-before)/n, "B/cell")29 b.ReportMetric(float64(after-before)/n-valueBytes, "B/cell-stored")30 runtime.KeepAlive(s)31 }32 })33 b.Run("pivot-8191", func(b *testing.B) {34 for b.Loop() {35 src := stress.Table(stress.Rows-1, 8)36 r := sheet.NewRect(sheet.Addr{}, sheet.Addr{Col: 7, Row: stress.Rows - 1})37 p := sheet.NewPivot(src, r)38 p.Rows = []sheet.PivotGroup{{Col: 0}}39 p.Values = []sheet.PivotValue{{Col: 2, Summarize: sheet.SumBy}, {Col: 3, Summarize: sheet.CountABy}}40 before := heap()41 pv, err := src.Book().CreatePivot(src, r, "", p)42 if err != nil {43 b.Fatal(err)44 }45 after := heap()46 b.ReportMetric(float64(after-before)/float64(pv.Len()), "B/cell")47 runtime.KeepAlive(pv)48 }49 })50}