MCPcopy Create free account
hub / github.com/apache/datafusion / benchmark_query

Method benchmark_query

benchmarks/src/clickbench.rs:246–284  ·  view source on GitHub ↗
(
        &self,
        sql: &str,
        query_id: usize,
        ctx: &SessionContext,
    )

Source from the content-addressed store, hash-verified

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

Callers 1

runMethod · 0.45

Calls 12

print_memory_statsFunction · 0.85
collectMethod · 0.80
sqlMethod · 0.80
sumMethod · 0.80
showMethod · 0.80
explain_with_optionsMethod · 0.80
iterationsMethod · 0.45
pushMethod · 0.45
mapMethod · 0.45
iterMethod · 0.45
with_formatMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected