(
&self,
sql: &str,
query_id: usize,
ctx: &SessionContext,
)
| 244 | } |
| 245 | |
| 246 | async fn benchmark_query( |
| 247 | &self, |
| 248 | sql: &str, |
| 249 | query_id: usize, |
| 250 | ctx: &SessionContext, |
| 251 | ) -> Result<Vec<QueryResult>> { |
| 252 | println!("Q{query_id}: {sql}"); |
| 253 | |
| 254 | let mut millis = Vec::with_capacity(self.iterations()); |
| 255 | let mut query_results = vec![]; |
| 256 | for i in 0..self.iterations() { |
| 257 | let start = Instant::now(); |
| 258 | let results = ctx.sql(sql).await?.collect().await?; |
| 259 | let elapsed = start.elapsed(); |
| 260 | let ms = elapsed.as_secs_f64() * 1000.0; |
| 261 | millis.push(ms); |
| 262 | let row_count: usize = results.iter().map(|b| b.num_rows()).sum(); |
| 263 | println!( |
| 264 | "Query {query_id} iteration {i} took {ms:.1} ms and returned {row_count} rows" |
| 265 | ); |
| 266 | query_results.push(QueryResult { elapsed, row_count }) |
| 267 | } |
| 268 | if self.common.debug { |
| 269 | ctx.sql(sql) |
| 270 | .await? |
| 271 | .explain_with_options( |
| 272 | ExplainOption::default().with_format(ExplainFormat::Tree), |
| 273 | )? |
| 274 | .show() |
| 275 | .await?; |
| 276 | } |
| 277 | let avg = millis.iter().sum::<f64>() / millis.len() as f64; |
| 278 | println!("Query {query_id} avg time: {avg:.2} ms"); |
| 279 | |
| 280 | // Print memory usage stats using mimalloc (only when compiled with --features mimalloc_extended) |
| 281 | print_memory_stats(); |
| 282 | |
| 283 | Ok(query_results) |
| 284 | } |
| 285 | |
| 286 | /// Registers the `hits.parquet` as a table named `hits` |
| 287 | /// If sorted_by is specified, uses CREATE EXTERNAL TABLE with WITH ORDER |
no test coverage detected