@@ -18,15 +18,25 @@ macro_rules! test_type_def {
1818 } ;
1919}
2020
21+ #[ macro_export]
22+ macro_rules! query {
23+ ( $query: expr_2021) => {
24+ $crate:: compiler:: expression:: Expr :: Query ( $crate:: compiler:: expression:: Query :: new(
25+ $crate:: compiler:: expression:: Target :: External ( $crate:: path:: PathPrefix :: Event ) ,
26+ $crate:: path:: parse_value_path( $query) . expect( "invalid path" ) ,
27+ ) )
28+ } ;
29+ }
30+
2131#[ macro_export]
2232macro_rules! func_args {
2333 ( ) => (
24- :: std:: collections:: HashMap :: <& ' static str , $crate:: value :: Value >:: default ( )
34+ :: std:: collections:: HashMap :: <& ' static str , $crate:: compiler :: expression :: Expr >:: default ( )
2535 ) ;
2636 ( $( $k: tt: $v: expr_2021) ,+ $( , ) ?) => {
27- vec! [ $( ( stringify!( $k) , $v . into( ) ) ) ,+]
37+ [ $( ( stringify!( $k) , $crate :: value :: Value :: from ( $v ) . into( ) ) ) ,+]
2838 . into_iter( )
29- . collect:: <:: std:: collections:: HashMap <& ' static str , $crate:: value :: Value >>( )
39+ . collect:: <:: std:: collections:: HashMap <& ' static str , $crate:: compiler :: expression :: Expr >>( )
3040 } ;
3141}
3242
@@ -58,6 +68,34 @@ macro_rules! bench_function {
5868 } ;
5969}
6070
71+ #[ macro_export]
72+ macro_rules! bench_query_function {
73+ ( $name: tt => $func: path; $( $case: ident { args: $args: expr_2021, event: $event: expr_2021, want: $( Ok ( $ok: expr_2021) ) ? $( Err ( $err: expr_2021) ) ? $( , ) * } ) +) => {
74+ fn $name( c: & mut criterion:: Criterion ) {
75+ let mut group = c. benchmark_group( & format!( "vrl_stdlib/functions/{}" , stringify!( $name) ) ) ;
76+ group. throughput( criterion:: Throughput :: Elements ( 1 ) ) ;
77+ $(
78+ group. bench_function( & stringify!( $case) . to_string( ) , |b| {
79+ let mut state = $crate:: compiler:: state:: TypeState :: default ( ) ;
80+
81+ let ( expression, want) = $crate:: __prep_bench_or_test!( $func, & state, $args, $( Ok ( $crate:: value:: Value :: from( $ok) ) ) ? $( Err ( $err. to_owned( ) ) ) ?) ;
82+ let expression = expression. unwrap( ) ;
83+ let mut runtime_state = $crate:: compiler:: state:: RuntimeState :: default ( ) ;
84+ let mut target: $crate:: value:: Value = $event. into( ) ;
85+ let tz = $crate:: compiler:: TimeZone :: Named ( chrono_tz:: Tz :: UTC ) ;
86+ let mut ctx = $crate:: compiler:: Context :: new( & mut target, & mut runtime_state, & tz) ;
87+
88+ b. iter( || {
89+ let got = expression. resolve( & mut ctx) . map_err( |e| e. to_string( ) ) ;
90+ debug_assert_eq!( got, want) ;
91+ got
92+ } )
93+ } ) ;
94+ ) +
95+ }
96+ } ;
97+ }
98+
6199#[ macro_export]
62100macro_rules! test_function {
63101
0 commit comments