MCPcopy
hub / github.com/expr-lang/expr / BenchmarkVM

Function BenchmarkVM

vm/vm_bench_test.go:14–78  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

12)
13
14func BenchmarkVM(b *testing.B) {
15 cases := []struct {
16 name, input string
17 }{
18 {"function calls", `
19func(
20 func(
21 func(func(a, 'a', 1, nil), func(a, 'a', 1, nil), func(a, 'a', 1, nil)),
22 func(func(a, 'a', 1, nil), func(a, 'a', 1, nil), func(a, 'a', 1, nil)),
23 func(func(a, 'a', 1, nil), func(a, 'a', 1, nil), func(a, 'a', 1, nil)),
24 ),
25 func(
26 func(func(a, 'a', 1, nil), func(a, 'a', 1, nil), func(a, 'a', 1, nil)),
27 func(func(a, 'a', 1, nil), func(a, 'a', 1, nil), func(a, 'a', 1, nil)),
28 func(func(a, 'a', 1, nil), func(a, 'a', 1, nil), func(a, 'a', 1, nil)),
29 ),
30 func(
31 func(func(a, 'a', 1, nil), func(a, 'a', 1, nil), func(a, 'a', 1, nil)),
32 func(func(a, 'a', 1, nil), func(a, 'a', 1, nil), func(a, 'a', 1, nil)),
33 func(func(a, 'a', 1, nil), func(a, 'a', 1, nil), func(a, 'a', 1, nil)),
34 )
35)
36 `},
37 }
38
39 a := new(recursive)
40 for i, b := 0, a; i < 40*4; i++ {
41 b.Inner = new(recursive)
42 b = b.Inner
43 }
44
45 f := func(params ...any) (any, error) { return nil, nil }
46 env := map[string]any{
47 "a": a,
48 "b": true,
49 "func": f,
50 }
51 config := conf.New(env)
52 expr.Function("func", f, f)(config)
53 config.Check()
54
55 for _, c := range cases {
56 tree, err := checker.ParseCheck(c.input, config)
57 if err != nil {
58 b.Fatal(c.input, "parse and check", err)
59 }
60 prog, err := compiler.Compile(tree, config)
61 if err != nil {
62 b.Fatal(c.input, "compile", err)
63 }
64 //b.Logf("disassembled:\n%s", prog.Disassemble())
65 //b.FailNow()
66 runtime.GC()
67
68 var vm vm.VM
69 b.Run("name="+c.name, func(b *testing.B) {
70 for i := 0; i < b.N; i++ {
71 _, err = vm.Run(prog, env)

Callers

nothing calls this directly

Calls 6

RunMethod · 0.95
NewFunction · 0.92
FunctionFunction · 0.92
ParseCheckFunction · 0.92
CompileFunction · 0.92
CheckMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…