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

Function Benchmark_sortBy

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

Source from the content-addressed store, hash-verified

519}
520
521func Benchmark_sortBy(b *testing.B) {
522 type Foo struct {
523 Value int
524 }
525 arr := []any{55, 58, 42, 61, 75, 52, 64, 62, 16, 79, 40, 14, 50, 76, 23, 2, 5, 80, 89, 51, 21, 96, 91, 13, 71, 82, 65, 63, 11, 17, 94, 81, 74, 4, 97, 1, 39, 3, 28, 8, 84, 90, 47, 85, 7, 56, 49, 93, 33, 12, 19, 60, 86, 100, 44, 45, 36, 72, 95, 77, 34, 92, 24, 73, 18, 38, 43, 26, 41, 69, 67, 57, 9, 27, 66, 87, 46, 35, 59, 70, 10, 20, 53, 15, 32, 98, 68, 31, 54, 25, 83, 88, 22, 48, 29, 37, 6, 78, 99, 30}
526 env := map[string]any{
527 "arr": make([]Foo, len(arr)),
528 }
529 for i, v := range arr {
530 env["arr"].([]Foo)[i] = Foo{Value: v.(int)}
531 }
532
533 program, err := expr.Compile(`sortBy(arr, .Value)`, expr.Env(env))
534 require.NoError(b, err)
535
536 var out any
537 b.ResetTimer()
538 for n := 0; n < b.N; n++ {
539 out, _ = vm.Run(program, env)
540 }
541 b.StopTimer()
542
543 require.Equal(b, 1, out.([]any)[0].(Foo).Value)
544 require.Equal(b, 100, out.([]any)[99].(Foo).Value)
545}
546
547func Benchmark_groupBy(b *testing.B) {
548 program, err := expr.Compile(`groupBy(1..100, # % 7)[6]`)

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…