@@ -44,6 +44,11 @@ fn prepare_script_bench(path: &Path) -> PreparedScriptBench {
4444}
4545
4646fn bench_scripts ( c : & mut Criterion ) {
47+ let args: Vec < String > = std:: env:: args ( ) . collect ( ) ;
48+ let is_list = args. iter ( ) . any ( |arg| arg == "--list" ) ;
49+ let filter = args. iter ( ) . skip ( 1 ) . find ( |arg| !arg. starts_with ( '-' ) ) ;
50+ let filter_re = filter. and_then ( |f| regex:: Regex :: new ( f) . ok ( ) ) ;
51+
4752 let scripts_dir = Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) ) . join ( "scripts" ) ;
4853
4954 let scripts: Vec < _ > = walkdir:: WalkDir :: new ( & scripts_dir)
@@ -70,15 +75,25 @@ fn bench_scripts(c: &mut Criterion) {
7075 group. measurement_time ( Duration :: from_secs ( 5 ) ) ;
7176 }
7277
73- let path = path. to_path_buf ( ) ;
74- let mut prepared: Option < PreparedScriptBench > = None ;
78+ let should_run = !is_list
79+ && filter. is_none_or ( |f| {
80+ let full_name = format ! ( "{name}/Execution" ) ;
81+ if let Some ( re) = & filter_re {
82+ re. is_match ( & full_name)
83+ } else {
84+ full_name. contains ( f)
85+ }
86+ } ) ;
87+
88+ let mut prepared = should_run. then ( || prepare_script_bench ( path) ) ;
7589
7690 group. bench_function ( "Execution" , move |b| {
77- let prepared = prepared. get_or_insert_with ( || prepare_script_bench ( & path ) ) ;
78- let function = prepared. function . clone ( ) ;
79- let context = & mut prepared. context ;
91+ if let Some ( prepared) = prepared. as_mut ( ) {
92+ let function = prepared. function . clone ( ) ;
93+ let context = & mut prepared. context ;
8094
81- b. iter ( || function. call ( & JsValue :: undefined ( ) , & [ ] , context) ) ;
95+ b. iter ( || function. call ( & JsValue :: undefined ( ) , & [ ] , context) ) ;
96+ }
8297 } ) ;
8398 group. finish ( ) ;
8499 }
0 commit comments