pub struct BenchmarkResults { /* private fields */ }Expand description
Aggregated benchmark results
Implementations§
Source§impl BenchmarkResults
impl BenchmarkResults
Sourcepub fn summaries(&self) -> &HashMap<String, BenchmarkSummary>
pub fn summaries(&self) -> &HashMap<String, BenchmarkSummary>
Get summaries
Examples found in repository?
examples/comprehensive_benchmarking_demo.rs (line 118)
113fn print_performance_summary(results: &BenchmarkResults) {
114 println!("\n Performance Summary:");
115 println!(" ===================");
116
117 // Print summaries for each benchmark
118 for (name, summary) in results.summaries() {
119 println!(" {name}:");
120 println!(" - Mean time: {:.3}s", summary.mean_time.as_secs_f64());
121 println!(" - Min time: {:.3}s", summary.min_time.as_secs_f64());
122 println!(" - Max time: {:.3}s", summary.max_time.as_secs_f64());
123 println!(" - Success rate: {:.1}%", summary.success_rate * 100.0);
124 if let Some(memory) = summary.mean_memory {
125 println!(
126 " - Memory usage: {:.1} MB",
127 memory as f64 / 1024.0 / 1024.0
128 );
129 }
130 println!();
131 }
132}
133
134fn print_scaling_analysis(results: &BenchmarkResults) {
135 println!(" Scaling Analysis:");
136 println!(" =================");
137
138 // Group by algorithm type
139 let mut vqe_results = Vec::new();
140 let mut qaoa_results = Vec::new();
141 let mut qnn_results = Vec::new();
142
143 for (name, summary) in results.summaries() {
144 if name.starts_with("vqe_") {
145 vqe_results.push((name, summary));
146 } else if name.starts_with("qaoa_") {
147 qaoa_results.push((name, summary));
148 } else if name.starts_with("qnn_") {
149 qnn_results.push((name, summary));
150 }
151 }
152
153 // Analyze VQE scaling
154 if !vqe_results.is_empty() {
155 println!(" VQE Algorithm Scaling:");
156 vqe_results.sort_by_key(|(name, _)| (*name).clone());
157 for (name, summary) in vqe_results {
158 let qubits = extract_qubit_count(name);
159 println!(
160 " - {} qubits: {:.3}s",
161 qubits,
162 summary.mean_time.as_secs_f64()
163 );
164 }
165 println!(" - Scaling trend: Exponential (as expected for VQE)");
166 println!();
167 }
168
169 // Analyze QAOA scaling
170 if !qaoa_results.is_empty() {
171 println!(" QAOA Algorithm Scaling:");
172 qaoa_results.sort_by_key(|(name, _)| (*name).clone());
173 for (name, summary) in qaoa_results {
174 let qubits = extract_qubit_count(name);
175 println!(
176 " - {} qubits: {:.3}s",
177 qubits,
178 summary.mean_time.as_secs_f64()
179 );
180 }
181 println!(" - Scaling trend: Polynomial (as expected for QAOA)");
182 println!();
183 }
184
185 // Analyze QNN scaling
186 if !qnn_results.is_empty() {
187 println!(" QNN Algorithm Scaling:");
188 qnn_results.sort_by_key(|(name, _)| (*name).clone());
189 for (name, summary) in qnn_results {
190 let qubits = extract_qubit_count(name);
191 println!(
192 " - {} qubits: {:.3}s",
193 qubits,
194 summary.mean_time.as_secs_f64()
195 );
196 }
197 println!(" - Scaling trend: Polynomial (training overhead)");
198 println!();
199 }
200}
201
202fn print_memory_analysis(results: &BenchmarkResults) {
203 println!(" Memory Usage Analysis:");
204 println!(" =====================");
205
206 let mut memory_data = Vec::new();
207 for (name, summary) in results.summaries() {
208 if let Some(memory) = summary.mean_memory {
209 let qubits = extract_qubit_count(name);
210 memory_data.push((qubits, memory, name));
211 }
212 }
213
214 if !memory_data.is_empty() {
215 memory_data.sort_by_key(|(qubits, _, _)| *qubits);
216
217 println!(" Memory scaling by qubit count:");
218 for (qubits, memory, name) in memory_data {
219 println!(
220 " - {} qubits ({}): {:.1} MB",
221 qubits,
222 name,
223 memory as f64 / 1024.0 / 1024.0
224 );
225 }
226 println!(" - Expected scaling: O(2^n) for statevector simulation");
227 println!();
228 }
229
230 // Print recommendations
231 println!(" Recommendations:");
232 println!(" - Use statevector backend for circuits ≤ 12 qubits");
233 println!(" - Use MPS backend for larger circuits with limited entanglement");
234 println!(" - Consider circuit optimization for memory-constrained environments");
235}
236
237fn extract_qubit_count(benchmark_name: &str) -> usize {
238 // Extract number from strings like "vqe_4q_statevector", "qaoa_6q_mps", etc.
239 for part in benchmark_name.split('_') {
240 if part.ends_with('q') {
241 if let Ok(num) = part.trim_end_matches('q').parse::<usize>() {
242 return num;
243 }
244 }
245 }
246 0 // Default if not found
247}
248
249// Additional analysis functions
250fn analyze_backend_performance(results: &BenchmarkResults) {
251 println!(" Backend Performance Comparison:");
252 println!(" ==============================");
253
254 // Group results by backend type
255 let mut backend_performance = std::collections::HashMap::new();
256
257 for (name, summary) in results.summaries() {
258 let backend_type = extract_backend_type(name);
259 backend_performance
260 .entry(backend_type)
261 .or_insert_with(Vec::new)
262 .push(summary.mean_time.as_secs_f64());
263 }
264
265 for (backend, times) in backend_performance {
266 let avg_time = times.iter().sum::<f64>() / times.len() as f64;
267 println!(" - {backend} backend: {avg_time:.3}s average");
268 }
269}Sourcepub fn metadata(&self) -> &BenchmarkMetadata
pub fn metadata(&self) -> &BenchmarkMetadata
Get metadata
Trait Implementations§
Source§impl Clone for BenchmarkResults
impl Clone for BenchmarkResults
Source§fn clone(&self) -> BenchmarkResults
fn clone(&self) -> BenchmarkResults
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for BenchmarkResults
impl RefUnwindSafe for BenchmarkResults
impl Send for BenchmarkResults
impl Sync for BenchmarkResults
impl Unpin for BenchmarkResults
impl UnwindSafe for BenchmarkResults
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.