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

Method benchmark_query

benchmarks/src/tpch/run.rs:164–214  ·  view source on GitHub ↗
(
        &self,
        query_id: usize,
        scale_factor: f64,
        ctx: &SessionContext,
    )

Source from the content-addressed store, hash-verified

162 }
163
164 async fn benchmark_query(
165 &self,
166 query_id: usize,
167 scale_factor: f64,
168 ctx: &SessionContext,
169 ) -> Result<Vec<QueryResult>> {
170 let mut millis = vec![];
171 // run benchmark
172 let mut query_results = vec![];
173
174 let sql = &get_query_sql_for_scale_factor(query_id, scale_factor)?;
175
176 for i in 0..self.iterations() {
177 let start = Instant::now();
178
179 // query 15 is special, with 3 statements. the second statement is the one from which we
180 // want to capture the results
181 let mut result = vec![];
182 if query_id == 15 {
183 for (n, query) in sql.iter().enumerate() {
184 if n == 1 {
185 result = self.execute_query(ctx, query).await?;
186 } else {
187 self.execute_query(ctx, query).await?;
188 }
189 }
190 } else {
191 for query in sql {
192 result = self.execute_query(ctx, query).await?;
193 }
194 }
195
196 let elapsed = start.elapsed();
197 let ms = elapsed.as_secs_f64() * 1000.0;
198 millis.push(ms);
199 info!("output:\n\n{}\n\n", pretty_format_batches(&result)?);
200 let row_count = result.iter().map(|b| b.num_rows()).sum();
201 println!(
202 "Query {query_id} iteration {i} took {ms:.1} ms and returned {row_count} rows"
203 );
204 query_results.push(QueryResult { elapsed, row_count });
205 }
206
207 let avg = millis.iter().sum::<f64>() / millis.len() as f64;
208 println!("Query {query_id} avg time: {avg:.2} ms");
209
210 // Print memory stats using mimalloc (only when compiled with --features mimalloc_extended)
211 print_memory_stats();
212
213 Ok(query_results)
214 }
215
216 async fn register_tables(&self, ctx: &SessionContext) -> Result<()> {
217 for table in TPCH_TABLES {

Callers 1

runMethod · 0.45

Calls 9

print_memory_statsFunction · 0.85
sumMethod · 0.80
iterationsMethod · 0.45
iterMethod · 0.45
execute_queryMethod · 0.45
pushMethod · 0.45
mapMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected