@@ -120,40 +120,42 @@ fn setup_rayon() {
120120}
121121
122122fn benchmark_incremental ( criterion : & mut Criterion ) {
123- setup_rayon ( ) ;
123+ fn setup ( ) -> Case {
124+ let case = setup_case ( ) ;
125+ let result = case. db . check ( ) . unwrap ( ) ;
124126
125- criterion. bench_function ( "red_knot_check_file[incremental]" , |b| {
126- b. iter_batched_ref (
127- || {
128- let case = setup_case ( ) ;
129- case. db . check ( ) . unwrap ( ) ;
130-
131- case. fs
132- . write_file (
133- & case. re_path ,
134- format ! ( "{}\n # A comment\n " , source_text( & case. db, case. re) . as_str( ) ) ,
135- )
136- . unwrap ( ) ;
137-
138- case
139- } ,
140- |case| {
141- let Case { db, .. } = case;
127+ assert_eq ! ( result, EXPECTED_DIAGNOSTICS ) ;
142128
143- db. apply_changes (
144- vec ! [ ChangeEvent :: Changed {
145- path: case. re_path. clone( ) ,
146- kind: ChangedKind :: FileContent ,
147- } ] ,
148- None ,
149- ) ;
129+ case. fs
130+ . write_file (
131+ & case. re_path ,
132+ format ! ( "{}\n # A comment\n " , source_text( & case. db, case. re) . as_str( ) ) ,
133+ )
134+ . unwrap ( ) ;
150135
151- let result = db. check ( ) . unwrap ( ) ;
136+ case
137+ }
152138
153- assert_eq ! ( result, EXPECTED_DIAGNOSTICS ) ;
154- } ,
155- BatchSize :: SmallInput ,
139+ fn incremental ( case : & mut Case ) {
140+ let Case { db, .. } = case;
141+
142+ db. apply_changes (
143+ vec ! [ ChangeEvent :: Changed {
144+ path: case. re_path. clone( ) ,
145+ kind: ChangedKind :: FileContent ,
146+ } ] ,
147+ None ,
156148 ) ;
149+
150+ let result = db. check ( ) . unwrap ( ) ;
151+
152+ assert_eq ! ( result, EXPECTED_DIAGNOSTICS ) ;
153+ }
154+
155+ setup_rayon ( ) ;
156+
157+ criterion. bench_function ( "red_knot_check_file[incremental]" , |b| {
158+ b. iter_batched_ref ( setup, incremental, BatchSize :: SmallInput ) ;
157159 } ) ;
158160}
159161
0 commit comments