Skip to content

Commit

Permalink
cue: add a "decimal" benchmark
Browse files Browse the repository at this point in the history
    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í <[email protected]>
Change-Id: Ic7e2178c8fe8736870962d71d56b6c250af81ada
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/554904
Reviewed-by: Marcel van Lohuizen <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
  • Loading branch information
mvdan committed Jun 15, 2023
1 parent 12908b3 commit f3be10a
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 6 deletions.
16 changes: 10 additions & 6 deletions cue/testdata/benchmarks/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package benchmarks

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -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
}

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

0 comments on commit f3be10a

Please sign in to comment.