cat / 012
clone

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

Add criteria and lookup shapes to the stress benchmarks

Dami committed d0ad2d8
SUMIF, COUNTIFS and AVERAGEIF over whole columns, and VLOOKUP, MATCH
and XLOOKUP into a column of keys, so changes to the function library
have numbers for its criteria and lookup paths.
commit
d0ad2d89b2e46ae06edad2c238976edc6b13785a
parent
100955bb936c9c26436c4dbec3c1d8487a8c1853
author
Dami <dami.etoile@gmail.com>
1 file changed, +54 -0
Minternal/stress/gen.go54++++++++++++++++++++++++++++++
M internal/stress/gen.go +54 -0
@@ -111,6 +111,58 @@ func Sparse(n, stride, k int) *sheet.Sheet {
111111 return s112112 }113113 114+// Criteria is a table of n rows (a number, a category, an amount) and k115+// conditional aggregates over whole columns of it: SUMIF, COUNTIFS with116+// two conditions and AVERAGEIF in turn, each testing every row.117+func Criteria(n, k int) *sheet.Sheet {118+ s := sheet.New()119+ for row := range n {120+ load(s, at(0, row), fmt.Sprint(row%100))121+ load(s, at(1, row), fmt.Sprintf("c%d", row%10))122+ load(s, at(2, row), fmt.Sprint(row%7))123+ }124+ for i := range k {125+ var f string126+ switch i % 3 {127+ case 0:128+ f = fmt.Sprintf(`=SUMIF(B:B, "c%d", C:C)`, i%10)129+ case 1:130+ f = fmt.Sprintf(`=COUNTIFS(A:A, ">%d", B:B, "c%d")`, i%100, i%10)131+ default:132+ f = fmt.Sprintf(`=AVERAGEIF(A:A, "<%d", C:C)`, i%100)133+ }134+ load(s, at(4, i), f)135+ }136+ s.RecalcAll()137+ return s138+}139+140+// Lookup is n keys with a value beside each and k exact lookups into141+// them: VLOOKUP, MATCH and XLOOKUP in turn, each key found somewhere142+// along the column.143+func Lookup(n, k int) *sheet.Sheet {144+ s := sheet.New()145+ for row := range n {146+ load(s, at(0, row), fmt.Sprint(row))147+ load(s, at(1, row), fmt.Sprintf("v%d", row))148+ }149+ for i := range k {150+ key := (i * 37) % n151+ var f string152+ switch i % 3 {153+ case 0:154+ f = fmt.Sprintf("=VLOOKUP(%d, A:B, 2, FALSE)", key)155+ case 1:156+ f = fmt.Sprintf("=MATCH(%d, A:A, 0)", key)157+ default:158+ f = fmt.Sprintf("=XLOOKUP(%d, A:A, B:B)", key)159+ }160+ load(s, at(3, i), f)161+ }162+ s.RecalcAll()163+ return s164+}165+114166 // FanOut is one cell, A1, read directly by k formulas.115167 func FanOut(k int) *sheet.Sheet {116168 s := sheet.New()
@@ -256,5 +308,7 @@ func Shapes() []Shape {
256308 {"names-1000", func() *sheet.Sheet { return Names(1000) }, at(0, 50), "9"},257309 {"fanin-1000xSUM(A:A)", func() *sheet.Sheet { return FanInColumns(Rows, 1000) }, at(0, 4000), "7"},258310 {"sparse-1M", func() *sheet.Sheet { return Sparse(10000, 100, 1000) }, at(0, 500000), "5"},311+ {"criteria-60xSUMIF8192", func() *sheet.Sheet { return Criteria(Rows, 60) }, at(0, 4000), "7"},312+ {"lookup-300xVLOOKUP8192", func() *sheet.Sheet { return Lookup(Rows, 300) }, at(0, 4000), "4000"},259313 }260314 }