From 3bcf4a477733ea2a754837df1b0ba7d1cedce0a2 Mon Sep 17 00:00:00 2001 From: Marcel van Lohuizen Date: Tue, 20 Sep 2022 18:47:20 +0200 Subject: [PATCH] cue/testdata/benchmarks: add stats This is not tested for now, but rather to update once in a while. Signed-off-by: Marcel van Lohuizen Change-Id: I85b7059441f72bb6e9745eacf24fb3348f6f52d1 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/543679 Unity-Result: CUEcueckoo TryBot-Result: CUEcueckoo Reviewed-by: Roger Peppe --- cue/testdata/benchmarks/bench_test.go | 38 ++++++++++++++++++- cue/testdata/benchmarks/chain.txtar | 12 ++++++ cue/testdata/benchmarks/cycle.txtar | 11 ++++++ cue/testdata/benchmarks/deduparc.txtar | 11 ++++++ cue/testdata/benchmarks/dedupelem.txtar | 11 ++++++ cue/testdata/benchmarks/disjunction.txtar | 10 +++++ cue/testdata/benchmarks/listdedup.txtar | 12 ++++++ .../benchmarks/mergeddisjunction.txtar | 11 ++++++ 8 files changed, 115 insertions(+), 1 deletion(-) diff --git a/cue/testdata/benchmarks/bench_test.go b/cue/testdata/benchmarks/bench_test.go index 7073b78088e..b4130300e61 100644 --- a/cue/testdata/benchmarks/bench_test.go +++ b/cue/testdata/benchmarks/bench_test.go @@ -20,6 +20,9 @@ import ( "testing" "cuelang.org/go/cue" + "cuelang.org/go/internal/core/eval" + "cuelang.org/go/internal/core/runtime" + "cuelang.org/go/internal/cuetest" "cuelang.org/go/internal/cuetxtar" "golang.org/x/tools/txtar" ) @@ -41,11 +44,44 @@ func Benchmark(b *testing.B) { b.Fatal(err) } - inst := cue.Build(cuetxtar.Load(a, b.TempDir()))[0] + inst := cuetxtar.Load(a, b.TempDir())[0] if inst.Err != nil { b.Fatal(inst.Err) } + r := runtime.New() + + v, err := r.Build(nil, inst) + if err != nil { + b.Fatal(err) + } + e := eval.New(r) + ctx := e.NewContext(v) + v.Finalize(ctx) + + if cuetest.UpdateGoldenFiles { + const statsFile = "stats.txt" + var stats txtar.File + var statsPos int + for i, f := range a.Files { + if f.Name == statsFile { + stats = f + statsPos = i + break + } + } + if stats.Name == "" { + // At stats.txt as the first file. + a.Files = append([]txtar.File{{ + Name: statsFile, + }}, a.Files...) + } + + a.Files[statsPos].Data = []byte(ctx.Stats().String() + "\n\n") + + ioutil.WriteFile(name, txtar.Format(a), fi.Mode()) + } + b.Run(name, func(b *testing.B) { for i := 0; i < b.N; i++ { inst := cue.Build(cuetxtar.Load(a, b.TempDir()))[0] diff --git a/cue/testdata/benchmarks/chain.txtar b/cue/testdata/benchmarks/chain.txtar index 28a6d995d0c..539c1e0e8ae 100644 --- a/cue/testdata/benchmarks/chain.txtar +++ b/cue/testdata/benchmarks/chain.txtar @@ -1,3 +1,15 @@ +// TODO(perf): reduce number of Conjunctions +-- stats.txt -- +Leaks: 0 +Freed: 1001 +Reused: 999 +Allocs: 2 +Retain: 0 + +Unifications: 1001 +Conjuncts: 500501 +Disjuncts: 1001 + -- in.cue -- f1: string f2: f1 diff --git a/cue/testdata/benchmarks/cycle.txtar b/cue/testdata/benchmarks/cycle.txtar index 9cccfd9e753..d45cc620041 100644 --- a/cue/testdata/benchmarks/cycle.txtar +++ b/cue/testdata/benchmarks/cycle.txtar @@ -1,3 +1,14 @@ +-- stats.txt -- +Leaks: 0 +Freed: 25 +Reused: 15 +Allocs: 10 +Retain: 1 + +Unifications: 15 +Conjuncts: 30 +Disjuncts: 25 + -- in.cue -- sameValues: SmustBeF: { T: string | F diff --git a/cue/testdata/benchmarks/deduparc.txtar b/cue/testdata/benchmarks/deduparc.txtar index bd610cde5c2..6022ca33145 100644 --- a/cue/testdata/benchmarks/deduparc.txtar +++ b/cue/testdata/benchmarks/deduparc.txtar @@ -1,3 +1,14 @@ +-- stats.txt -- +Leaks: 0 +Freed: 11 +Reused: 6 +Allocs: 5 +Retain: 0 + +Unifications: 7 +Conjuncts: 29 +Disjuncts: 11 + -- in.cue -- package bench1 diff --git a/cue/testdata/benchmarks/dedupelem.txtar b/cue/testdata/benchmarks/dedupelem.txtar index a2035a25476..db52d059991 100644 --- a/cue/testdata/benchmarks/dedupelem.txtar +++ b/cue/testdata/benchmarks/dedupelem.txtar @@ -1,3 +1,14 @@ +-- stats.txt -- +Leaks: 0 +Freed: 16 +Reused: 10 +Allocs: 6 +Retain: 0 + +Unifications: 10 +Conjuncts: 94 +Disjuncts: 16 + -- in.cue -- package lpcorpus diff --git a/cue/testdata/benchmarks/disjunction.txtar b/cue/testdata/benchmarks/disjunction.txtar index 7ce9ca6b43c..a298167d0ff 100644 --- a/cue/testdata/benchmarks/disjunction.txtar +++ b/cue/testdata/benchmarks/disjunction.txtar @@ -1,5 +1,15 @@ // Triggering recomputation of disjunctions on each branch results // in exponential run time. Ensure this does not happen. +-- stats.txt -- +Leaks: 0 +Freed: 82 +Reused: 74 +Allocs: 8 +Retain: 0 + +Unifications: 4 +Conjuncts: 143 +Disjuncts: 82 -- in.cue -- x: a0: {} diff --git a/cue/testdata/benchmarks/listdedup.txtar b/cue/testdata/benchmarks/listdedup.txtar index 9f4c5b11221..b89f29eae38 100644 --- a/cue/testdata/benchmarks/listdedup.txtar +++ b/cue/testdata/benchmarks/listdedup.txtar @@ -1,6 +1,18 @@ #Issue: 758 #Issue: 1044 +// TODO(perf): reduce number of conjunctions and disjunctions. +-- stats.txt -- +Leaks: 0 +Freed: 24096 +Reused: 24051 +Allocs: 45 +Retain: 1 + +Unifications: 18724 +Conjuncts: 100730 +Disjuncts: 24096 + -- in.cue -- A: #Task B: #steps: #Script & {mount: [A]} diff --git a/cue/testdata/benchmarks/mergeddisjunction.txtar b/cue/testdata/benchmarks/mergeddisjunction.txtar index 73dab317209..0eb54b0b5da 100644 --- a/cue/testdata/benchmarks/mergeddisjunction.txtar +++ b/cue/testdata/benchmarks/mergeddisjunction.txtar @@ -9,6 +9,17 @@ // disjunct. // // Issue #651 +-- stats.txt -- +Leaks: 0 +Freed: 163 +Reused: 157 +Allocs: 6 +Retain: 0 + +Unifications: 99 +Conjuncts: 290 +Disjuncts: 163 + -- in.cue -- list: [ 0, 1, 2, 3, 4, 5, 6, 7, 8,