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

Function Benchmark_arrayIndex

bench_test.go:223–243  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

221}
222
223func Benchmark_arrayIndex(b *testing.B) {
224 env := map[string]any{
225 "arr": make([]int, 100),
226 }
227 for i := 0; i < 100; i++ {
228 env["arr"].([]int)[i] = i
229 }
230
231 program, err := expr.Compile(`arr[50]`, expr.Env(env))
232 require.NoError(b, err)
233
234 var out any
235 b.ResetTimer()
236 for n := 0; n < b.N; n++ {
237 out, err = vm.Run(program, env)
238 }
239 b.StopTimer()
240
241 require.NoError(b, err)
242 require.Equal(b, 50, out)
243}
244
245func Benchmark_envStruct(b *testing.B) {
246 type Price struct {

Callers

nothing calls this directly

Calls 5

CompileFunction · 0.92
EnvStruct · 0.92
NoErrorFunction · 0.92
RunFunction · 0.92
EqualFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…