From f3be10a2114c5a97bdde29266cea8dc88e0daf0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Fri, 2 Jun 2023 16:32:24 +0100 Subject: [PATCH] cue: add a "decimal" benchmark MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit goos: linux goarch: amd64 pkg: cuelang.org/go/cue/testdata/benchmarks cpu: AMD Ryzen 7 PRO 5850U with Radeon Graphics │ apd-v2-24 │ │ sec/op │ /decimal.txtar-8 4.982m ± 1% │ apd-v2-24 │ │ B/op │ /decimal.txtar-8 1.873Mi ± 0% │ apd-v2-24 │ │ allocs/op │ /decimal.txtar-8 29.72k ± 0% Signed-off-by: Daniel Martí Change-Id: Ic7e2178c8fe8736870962d71d56b6c250af81ada Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/554904 Reviewed-by: Marcel van Lohuizen TryBot-Result: CUEcueckoo --- cue/testdata/benchmarks/bench_test.go | 16 ++++--- cue/testdata/benchmarks/decimal.txtar | 65 +++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 cue/testdata/benchmarks/decimal.txtar diff --git a/cue/testdata/benchmarks/bench_test.go b/cue/testdata/benchmarks/bench_test.go index b5d7aca8136..2e2417a4758 100644 --- a/cue/testdata/benchmarks/bench_test.go +++ b/cue/testdata/benchmarks/bench_test.go @@ -15,7 +15,6 @@ package benchmarks import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -29,14 +28,14 @@ import ( ) func Benchmark(b *testing.B) { - files, err := ioutil.ReadDir(".") + entries, err := os.ReadDir(".") if err != nil { b.Fatal(err) } - for _, fi := range files { - name := fi.Name() - if fi.IsDir() || filepath.Ext(name) != ".txtar" { + for _, entry := range entries { + name := entry.Name() + if entry.IsDir() || filepath.Ext(name) != ".txtar" { continue } @@ -80,10 +79,15 @@ func Benchmark(b *testing.B) { a.Files[statsPos].Data = []byte(ctx.Stats().String() + "\n\n") - os.WriteFile(name, txtar.Format(a), fi.Mode()) + info, err := entry.Info() + if err != nil { + b.Fatal(err) + } + os.WriteFile(name, txtar.Format(a), info.Mode()) } b.Run(name, func(b *testing.B) { + b.ReportAllocs() for i := 0; i < b.N; i++ { inst := cue.Build(cuetxtar.Load(a, b.TempDir()))[0] if inst.Err != nil { diff --git a/cue/testdata/benchmarks/decimal.txtar b/cue/testdata/benchmarks/decimal.txtar new file mode 100644 index 00000000000..adfdb77a34e --- /dev/null +++ b/cue/testdata/benchmarks/decimal.txtar @@ -0,0 +1,65 @@ +-- stats.txt -- +Leaks: 0 +Freed: 11 +Reused: 8 +Allocs: 3 +Retain: 0 + +Unifications: 11 +Conjuncts: 11 +Disjuncts: 11 + +-- in.cue -- +out: [ + 123.45 + 987.65, + 123.45 - 987.65, + 123.45 * 987.65, + 123.45 / 987.65, + + // whole integers + 2 + 3, + 7 - 1, + 5 * 10, + 20 / 4, + + 1 / 3, // fill all digits +] +-- out/compile -- +--- in.cue +{ + out: [ + (123.45 + 987.65), + (123.45 - 987.65), + (123.45 * 987.65), + (123.45 / 987.65), + (2 + 3), + (7 - 1), + (5 * 10), + (20 / 4), + (1 / 3), + ] +} +-- out/eval/stats -- +Leaks: 0 +Freed: 11 +Reused: 8 +Allocs: 3 +Retain: 0 + +Unifications: 11 +Conjuncts: 11 +Disjuncts: 11 +-- out/eval -- +(struct){ + out: (#list){ + 0: (float){ 1111.10 } + 1: (float){ -864.20 } + 2: (float){ 121925.3925 } + 3: (float){ 0.124993671847314332000203 } + 4: (int){ 5 } + 5: (int){ 6 } + 6: (int){ 50 } + 7: (float){ 5 } + 8: (float){ 0.333333333333333333333333 } + } +}