Skip to content

Commit

Permalink
cue/testdata/benchmarks: add stats
Browse files Browse the repository at this point in the history
This is not tested for now, but rather to update once in a while.

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: I85b7059441f72bb6e9745eacf24fb3348f6f52d1
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/543679
Unity-Result: CUEcueckoo <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
Reviewed-by: Roger Peppe <[email protected]>
  • Loading branch information
mpvl committed Sep 23, 2022
1 parent f5c3e4e commit 3bcf4a4
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 1 deletion.
38 changes: 37 additions & 1 deletion cue/testdata/benchmarks/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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]
Expand Down
12 changes: 12 additions & 0 deletions cue/testdata/benchmarks/chain.txtar
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 11 additions & 0 deletions cue/testdata/benchmarks/cycle.txtar
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 11 additions & 0 deletions cue/testdata/benchmarks/deduparc.txtar
Original file line number Diff line number Diff line change
@@ -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

Expand Down
11 changes: 11 additions & 0 deletions cue/testdata/benchmarks/dedupelem.txtar
Original file line number Diff line number Diff line change
@@ -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

Expand Down
10 changes: 10 additions & 0 deletions cue/testdata/benchmarks/disjunction.txtar
Original file line number Diff line number Diff line change
@@ -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: {}
Expand Down
12 changes: 12 additions & 0 deletions cue/testdata/benchmarks/listdedup.txtar
Original file line number Diff line number Diff line change
@@ -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]}
Expand Down
11 changes: 11 additions & 0 deletions cue/testdata/benchmarks/mergeddisjunction.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3bcf4a4

Please sign in to comment.