| 573 | } |
| 574 | |
| 575 | func Benchmark_min(b *testing.B) { |
| 576 | 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} |
| 577 | env := map[string]any{"arr": arr} |
| 578 | |
| 579 | program, err := expr.Compile(`min(arr)`, expr.Env(env)) |
| 580 | require.NoError(b, err) |
| 581 | |
| 582 | var out any |
| 583 | b.ResetTimer() |
| 584 | for n := 0; n < b.N; n++ { |
| 585 | out, _ = vm.Run(program, env) |
| 586 | } |
| 587 | b.StopTimer() |
| 588 | |
| 589 | require.Equal(b, 1, out) |
| 590 | } |
| 591 | |
| 592 | func Benchmark_max(b *testing.B) { |
| 593 | 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} |