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

Method benchmark_query

benchmarks/src/sort_pushdown.rs:159–196  ·  view source on GitHub ↗
(&self, query_id: usize)

Source from the content-addressed store, hash-verified

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 {

Callers 1

runMethod · 0.45

Calls 15

newFunction · 0.85
print_memory_statsFunction · 0.85
load_queryMethod · 0.80
build_runtimeMethod · 0.80
with_default_featuresMethod · 0.80
configMethod · 0.45
buildMethod · 0.45
with_runtime_envMethod · 0.45
with_configMethod · 0.45
register_tablesMethod · 0.45
iterationsMethod · 0.45
execute_queryMethod · 0.45

Tested by

no test coverage detected