(&self, query_id: usize)
| 305 | } |
| 306 | |
| 307 | async fn benchmark_query(&self, query_id: usize) -> Result<Vec<QueryResult>> { |
| 308 | let mut config = self |
| 309 | .common |
| 310 | .config()? |
| 311 | .with_collect_statistics(!self.disable_statistics); |
| 312 | config.options_mut().optimizer.prefer_hash_join = self.prefer_hash_join; |
| 313 | config.options_mut().execution.hash_join_buffering_capacity = |
| 314 | self.hash_join_buffering_capacity; |
| 315 | let rt = self.common.build_runtime()?; |
| 316 | let ctx = SessionContext::new_with_config_rt(config, rt); |
| 317 | |
| 318 | // register tables |
| 319 | self.register_tables(&ctx).await?; |
| 320 | |
| 321 | let mut millis = vec![]; |
| 322 | // run benchmark |
| 323 | let mut query_results = vec![]; |
| 324 | for i in 0..self.iterations() { |
| 325 | let start = Instant::now(); |
| 326 | |
| 327 | let query_id_str = map_query_id_to_str(query_id); |
| 328 | let sql = &get_query_sql(query_id_str)?; |
| 329 | |
| 330 | let mut result = vec![]; |
| 331 | |
| 332 | for query in sql { |
| 333 | result = self.execute_query(&ctx, query).await?; |
| 334 | } |
| 335 | |
| 336 | let elapsed = start.elapsed(); //.as_secs_f64() * 1000.0; |
| 337 | let ms = elapsed.as_secs_f64() * 1000.0; |
| 338 | millis.push(ms); |
| 339 | info!("output:\n\n{}\n\n", pretty_format_batches(&result)?); |
| 340 | let row_count = result.iter().map(|b| b.num_rows()).sum(); |
| 341 | println!( |
| 342 | "Query {query_id} iteration {i} took {ms:.1} ms and returned {row_count} rows" |
| 343 | ); |
| 344 | query_results.push(QueryResult { elapsed, row_count }); |
| 345 | } |
| 346 | |
| 347 | let avg = millis.iter().sum::<f64>() / millis.len() as f64; |
| 348 | println!("Query {query_id} avg time: {avg:.2} ms"); |
| 349 | |
| 350 | // Print memory usage stats using mimalloc (only when compiled with --features mimalloc_extended) |
| 351 | print_memory_stats(); |
| 352 | |
| 353 | Ok(query_results) |
| 354 | } |
| 355 | |
| 356 | async fn register_tables(&self, ctx: &SessionContext) -> Result<()> { |
| 357 | for table in IMDB_TABLES { |
no test coverage detected