(&self, query_id: usize)
| 157 | } |
| 158 | |
| 159 | async fn benchmark_query(&self, query_id: usize) -> Result<Vec<QueryResult>> { |
| 160 | let sql = self.load_query(query_id)?; |
| 161 | |
| 162 | let config = self.common.config()?; |
| 163 | let rt = self.common.build_runtime()?; |
| 164 | let state = SessionStateBuilder::new() |
| 165 | .with_config(config) |
| 166 | .with_runtime_env(rt) |
| 167 | .with_default_features() |
| 168 | .build(); |
| 169 | let ctx = SessionContext::from(state); |
| 170 | |
| 171 | self.register_tables(&ctx).await?; |
| 172 | |
| 173 | let mut millis = vec![]; |
| 174 | let mut query_results = vec![]; |
| 175 | for i in 0..self.iterations() { |
| 176 | let start = Instant::now(); |
| 177 | |
| 178 | let row_count = self.execute_query(&ctx, sql.as_str()).await?; |
| 179 | |
| 180 | let elapsed = start.elapsed(); |
| 181 | let ms = elapsed.as_secs_f64() * 1000.0; |
| 182 | millis.push(ms); |
| 183 | |
| 184 | println!( |
| 185 | "Query {query_id} iteration {i} took {ms:.1} ms and returned {row_count} rows" |
| 186 | ); |
| 187 | query_results.push(QueryResult { elapsed, row_count }); |
| 188 | } |
| 189 | |
| 190 | let avg = millis.iter().sum::<f64>() / millis.len() as f64; |
| 191 | println!("Query {query_id} avg time: {avg:.2} ms"); |
| 192 | |
| 193 | print_memory_stats(); |
| 194 | |
| 195 | Ok(query_results) |
| 196 | } |
| 197 | |
| 198 | async fn register_tables(&self, ctx: &SessionContext) -> Result<()> { |
| 199 | for table in Self::TABLES { |
no test coverage detected