Benchmark query `query_id` in `SORT_QUERIES`
(&self, query_id: usize)
| 208 | |
| 209 | /// Benchmark query `query_id` in `SORT_QUERIES` |
| 210 | async fn benchmark_query(&self, query_id: usize) -> Result<Vec<QueryResult>> { |
| 211 | let config = self.common.config()?; |
| 212 | let rt = self.common.build_runtime()?; |
| 213 | let state = SessionStateBuilder::new() |
| 214 | .with_config(config) |
| 215 | .with_runtime_env(rt) |
| 216 | .with_default_features() |
| 217 | .build(); |
| 218 | let ctx = SessionContext::from(state); |
| 219 | |
| 220 | // register tables |
| 221 | self.register_tables(&ctx).await?; |
| 222 | |
| 223 | let mut millis = vec![]; |
| 224 | // run benchmark |
| 225 | let mut query_results = vec![]; |
| 226 | for i in 0..self.iterations() { |
| 227 | let start = Instant::now(); |
| 228 | |
| 229 | let query_idx = query_id - 1; // 1-indexed -> 0-indexed |
| 230 | let base_sql = Self::SORT_QUERIES[query_idx].to_string(); |
| 231 | let sql = if let Some(limit) = self.limit { |
| 232 | format!("{base_sql} LIMIT {limit}") |
| 233 | } else { |
| 234 | base_sql |
| 235 | }; |
| 236 | |
| 237 | let row_count = self.execute_query(&ctx, sql.as_str()).await?; |
| 238 | |
| 239 | let elapsed = start.elapsed(); //.as_secs_f64() * 1000.0; |
| 240 | let ms = elapsed.as_secs_f64() * 1000.0; |
| 241 | millis.push(ms); |
| 242 | |
| 243 | println!( |
| 244 | "Query {query_id} iteration {i} took {ms:.1} ms and returned {row_count} rows" |
| 245 | ); |
| 246 | query_results.push(QueryResult { elapsed, row_count }); |
| 247 | } |
| 248 | |
| 249 | let avg = millis.iter().sum::<f64>() / millis.len() as f64; |
| 250 | println!("Query {query_id} avg time: {avg:.2} ms"); |
| 251 | |
| 252 | // Print memory usage stats using mimalloc (only when compiled with --features mimalloc_extended) |
| 253 | print_memory_stats(); |
| 254 | |
| 255 | Ok(query_results) |
| 256 | } |
| 257 | |
| 258 | async fn register_tables(&self, ctx: &SessionContext) -> Result<()> { |
| 259 | for table in Self::SORT_TABLES { |
no test coverage detected