Movatterモバイル変換


[0]ホーム

URL:


bench

package
v0.26.1Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2025 License:Apache-2.0, BSD-3-ClauseImports:6Imported by:0

Details

Repository

github.com/google/cel-go

Links

Documentation

Overview

Package bench defines a structure for benchmarked tests against custom CEL environments.

Index

Constants

This section is empty.

Variables

View Source
var (// ReferenceCases represent canonical CEL expressions for common use cases.ReferenceCases = []*Case{{Expr: `string_value == 'value'`,Options: []cel.EnvOption{cel.Variable("string_value",cel.StringType),},In: map[string]any{"string_value": "value",},Out:types.True,},{Expr: `string_value != 'value'`,Options: []cel.EnvOption{cel.Variable("string_value",cel.StringType),},In: map[string]any{"string_value": "value",},Out:types.False,},{Expr: `'value' in list_value`,Options: []cel.EnvOption{cel.Variable("list_value",cel.ListType(cel.StringType)),},In: map[string]any{"list_value": []string{"a", "b", "c", "value"},},Out:types.True,},{Expr: `!('value' in list_value)`,Options: []cel.EnvOption{cel.Variable("list_value",cel.ListType(cel.StringType)),},In: map[string]any{"list_value": []string{"a", "b", "c", "d"},},Out:types.True,},{Expr: `x in ['a', 'b', 'c', 'd']`,Options: []cel.EnvOption{cel.Variable("x",cel.StringType),},In: map[string]any{"x": "c",},Out:types.True,},{Expr: `!(x in ['a', 'b', 'c', 'd'])`,Options: []cel.EnvOption{cel.Variable("x",cel.StringType),},In: map[string]any{"x": "e",},Out:types.True,},{Expr: `x in list_value`,Options: []cel.EnvOption{cel.Variable("x",cel.StringType),cel.Variable("list_value",cel.ListType(cel.StringType)),},In: map[string]any{"x":          "c","list_value": []string{"a", "b", "c", "d"},},Out:types.True,},{Expr: `!(x in list_value)`,Options: []cel.EnvOption{cel.Variable("x",cel.StringType),cel.Variable("list_value",cel.ListType(cel.StringType)),},In: map[string]any{"x":          "e","list_value": []string{"a", "b", "c", "d"},},Out:types.True,},{Expr: `list_value.exists(e, e.contains('cd'))`,Options: []cel.EnvOption{cel.Variable("list_value",cel.ListType(cel.StringType)),},In: map[string]any{"list_value": []string{"abc", "bcd", "cde", "def"},},Out:types.True,},{Expr: `list_value.exists(e, e.startsWith('cd'))`,Options: []cel.EnvOption{cel.Variable("list_value",cel.ListType(cel.StringType)),},In: map[string]any{"list_value": []string{"abc", "bcd", "cde", "def"},},Out:types.True,},{Expr: `list_value.exists(e, e.matches('cd*'))`,Options: []cel.EnvOption{cel.Variable("list_value",cel.ListType(cel.StringType)),},In: map[string]any{"list_value": []string{"abc", "bcd", "cde", "def"},},Out:types.True,},{Expr: `list_value.filter(e, e.matches('^cd+')) == ['cde']`,Options: []cel.EnvOption{cel.Variable("list_value",cel.ListType(cel.StringType)),},In: map[string]any{"list_value": []string{"abc", "bcd", "cde", "def"},},Out:types.True,},{Expr: `'formatted list: %s, size: %d'.format([['abc', 'cde'], 2])`,Options: []cel.EnvOption{ext.Strings(),},In:  map[string]any{},Out:types.String(`formatted list: ["abc", "cde"], size: 2`),},}// ReferenceDynamicEnvCases represent CEL expressions compiled in an extended environment.ReferenceDynamicEnvCases = []*DynamicEnvCase{{Expr: `a+b`,Options: func(b *testing.B) *cel.Env {stdenv, err :=cel.NewEnv(cel.Variable("a",cel.IntType),cel.Variable("b",cel.IntType))if err !=nil {b.Fatalf("cel.NewEnv() failed: %v", err)}return stdenv},},{Expr: `x == y && y == z`,Options: func(b *testing.B) *cel.Env {stdenv, err :=cel.NewEnv(cel.Variable("x",cel.IntType),cel.Variable("y",cel.IntType))if err !=nil {b.Fatalf("cel.NewEnv() failed: %v", err)}stdenv.Compile("x == y")stdenv, err = stdenv.Extend(cel.Variable("z",cel.IntType))if err !=nil {b.Fatalf("cel.Extend() failed: %v", err)}return stdenv},},{Expr: `x + y + z`,Options: func(b *testing.B) *cel.Env {stdenv, err :=cel.NewEnv(cel.Variable("x",cel.IntType),cel.Variable("y",cel.IntType))if err !=nil {b.Fatalf("cel.NewEnv() failed: %v", err)}stdenv.Compile("x + y")stdenv, err = stdenv.Extend(cel.Variable("z",cel.IntType))if err !=nil {b.Fatalf("cel.Extend() failed: %v", err)}return stdenv},},})

Functions

funcRunCase

func RunCase(b *testing.B, env *cel.Env, bc *Case)

RunCase evaluates a single test case against a custom environment, running three differentvariants of the expression: optimized, unoptimized, and trace.

* `optimized` - applies the cel.EvalOptions(cel.OptOptimize) flag.* `unoptimized` - no optimization flags applied.* `trace` - observes the evaluation state of an expression.

In many cases the evaluation times may be similar, but when running comparisons against thebaseline CEL environment, it may be useful to characterize the performance of the customenvironment against the baseline.

funcRunDynamicEnvCaseadded inv0.21.0

func RunDynamicEnvCase(b *testing.B, bc *DynamicEnvCase)

RunDynamicEnvCase runs a singular DynamicEnvCase.

funcRunReferenceCases

func RunReferenceCases(b *testing.B, env *cel.Env)

RunReferenceCases evaluates the set of ReferenceCases against a custom CEL environment.

See: bench_test.go for an example.

funcRunReferenceDynamicEnvCasesadded inv0.21.0

func RunReferenceDynamicEnvCases(b *testing.B)

RunReferenceDynamicEnvCases evaluates the set of ReferenceDynamicEnvCases.

Types

typeCase

type Case struct {// Expr is a human-readable expression which is expected to compile.Exprstring// Options indicate additional pieces of configuration such as CEL libraries, variables, and functions.Options []cel.EnvOption// In is expected to be a map[string]any or cel.Activation instance representing the input to the expression.Inany// Out is the expected CEL valued output.Outref.Val}

Case represents a human-readable expression and an expected output given an input

typeDynamicEnvCaseadded inv0.21.0

type DynamicEnvCase struct {// Expr is a human-readable expression which is expected to compile.Exprstring// Options indicate additional pieces of configuration such as CEL libraries, variables, and functions.Options func(b *testing.B) *cel.Env// In is expected to be a map[string]any or cel.Activation instance representing the input to the expression.Inany// Out is the expected CEL valued output.Outref.Val}

DynamicEnvCase represents an expression compiled in a dynamic environment.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp