@@ -213,12 +213,46 @@ fn run_ui_cargo() {
213213
214214fn main ( ) {
215215 set_var ( "CLIPPY_DISABLE_DOCS_LINKS" , "true" ) ;
216- run_ui ( ) ;
217- run_ui_toml ( ) ;
218- run_ui_cargo ( ) ;
219- run_internal_tests ( ) ;
220- rustfix_coverage_known_exceptions_accuracy ( ) ;
221- ui_cargo_toml_metadata ( ) ;
216+ // The SPEEDTEST_* env variables can be used to check Clippy's performance on your PR. It runs the
217+ // affected test 1000 times and gets the average.
218+ if let Ok ( speedtest) = std:: env:: var ( "SPEEDTEST" ) {
219+ println ! ( "----------- STARTING SPEEDTEST -----------" ) ;
220+ let f;
221+ match speedtest. as_str ( ) {
222+ "ui" => f = run_ui as fn ( ) ,
223+ "cargo" => f = run_ui_cargo as fn ( ) ,
224+ "toml" => f = run_ui_toml as fn ( ) ,
225+ "internal" => f = run_internal_tests as fn ( ) ,
226+ "rustfix-coverage-known-exceptions-accuracy" => f = rustfix_coverage_known_exceptions_accuracy as fn ( ) ,
227+ "ui-cargo-toml-metadata" => f = ui_cargo_toml_metadata ( ) as fn ( ) ,
228+
229+ _ => panic ! ( "unknown speedtest: {speedtest} || accepted speedtests are: [ui, cargo, toml, internal]" ) ,
230+ }
231+
232+ let iterations;
233+ if let Ok ( iterations_str) = std:: env:: var ( "SPEEDTEST_ITERATIONS" ) {
234+ iterations = iterations_str
235+ . parse :: < u64 > ( )
236+ . unwrap_or_else ( |_| panic ! ( "Couldn't parse `{}`, please use a valid u64" , iterations_str) ) ;
237+ } else {
238+ iterations = 1000 ;
239+ }
240+
241+ let mut sum = 0 ;
242+ for _ in 0 ..iterations {
243+ let start = std:: time:: Instant :: now ( ) ;
244+ f ( ) ;
245+ sum += start. elapsed ( ) . as_millis ( ) ;
246+ }
247+ println ! ( "average {} time: {} millis." , speedtest. to_uppercase( ) , sum / 1000 ) ;
248+ } else {
249+ run_ui ( ) ;
250+ run_ui_toml ( ) ;
251+ run_ui_cargo ( ) ;
252+ run_internal_tests ( ) ;
253+ rustfix_coverage_known_exceptions_accuracy ( ) ;
254+ ui_cargo_toml_metadata ( ) ;
255+ }
222256}
223257
224258const RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS : & [ & str ] = & [
0 commit comments