BenchmarkResults

Struct BenchmarkResults 

Source
pub struct BenchmarkResults { /* private fields */ }
Expand description

Aggregated benchmark results

Implementations§

Source§

impl BenchmarkResults

Source

pub fn summaries(&self) -> &HashMap<String, BenchmarkSummary>

Get summaries

Examples found in repository?
examples/comprehensive_benchmarking_demo.rs (line 125)
120fn print_performance_summary(results: &BenchmarkResults) {
121    println!("\n   Performance Summary:");
122    println!("   ===================");
123
124    // Print summaries for each benchmark
125    for (name, summary) in results.summaries() {
126        println!("   {name}:");
127        println!("     - Mean time: {:.3}s", summary.mean_time.as_secs_f64());
128        println!("     - Min time:  {:.3}s", summary.min_time.as_secs_f64());
129        println!("     - Max time:  {:.3}s", summary.max_time.as_secs_f64());
130        println!("     - Success rate: {:.1}%", summary.success_rate * 100.0);
131        if let Some(memory) = summary.mean_memory {
132            println!(
133                "     - Memory usage: {:.1} MB",
134                memory as f64 / 1024.0 / 1024.0
135            );
136        }
137        println!();
138    }
139}
140
141fn print_scaling_analysis(results: &BenchmarkResults) {
142    println!("   Scaling Analysis:");
143    println!("   =================");
144
145    // Group by algorithm type
146    let mut vqe_results = Vec::new();
147    let mut qaoa_results = Vec::new();
148    let mut qnn_results = Vec::new();
149
150    for (name, summary) in results.summaries() {
151        if name.starts_with("vqe_") {
152            vqe_results.push((name, summary));
153        } else if name.starts_with("qaoa_") {
154            qaoa_results.push((name, summary));
155        } else if name.starts_with("qnn_") {
156            qnn_results.push((name, summary));
157        }
158    }
159
160    // Analyze VQE scaling
161    if !vqe_results.is_empty() {
162        println!("   VQE Algorithm Scaling:");
163        vqe_results.sort_by_key(|(name, _)| (*name).clone());
164        for (name, summary) in vqe_results {
165            let qubits = extract_qubit_count(name);
166            println!(
167                "     - {} qubits: {:.3}s",
168                qubits,
169                summary.mean_time.as_secs_f64()
170            );
171        }
172        println!("     - Scaling trend: Exponential (as expected for VQE)");
173        println!();
174    }
175
176    // Analyze QAOA scaling
177    if !qaoa_results.is_empty() {
178        println!("   QAOA Algorithm Scaling:");
179        qaoa_results.sort_by_key(|(name, _)| (*name).clone());
180        for (name, summary) in qaoa_results {
181            let qubits = extract_qubit_count(name);
182            println!(
183                "     - {} qubits: {:.3}s",
184                qubits,
185                summary.mean_time.as_secs_f64()
186            );
187        }
188        println!("     - Scaling trend: Polynomial (as expected for QAOA)");
189        println!();
190    }
191
192    // Analyze QNN scaling
193    if !qnn_results.is_empty() {
194        println!("   QNN Algorithm Scaling:");
195        qnn_results.sort_by_key(|(name, _)| (*name).clone());
196        for (name, summary) in qnn_results {
197            let qubits = extract_qubit_count(name);
198            println!(
199                "     - {} qubits: {:.3}s",
200                qubits,
201                summary.mean_time.as_secs_f64()
202            );
203        }
204        println!("     - Scaling trend: Polynomial (training overhead)");
205        println!();
206    }
207}
208
209fn print_memory_analysis(results: &BenchmarkResults) {
210    println!("   Memory Usage Analysis:");
211    println!("   =====================");
212
213    let mut memory_data = Vec::new();
214    for (name, summary) in results.summaries() {
215        if let Some(memory) = summary.mean_memory {
216            let qubits = extract_qubit_count(name);
217            memory_data.push((qubits, memory, name));
218        }
219    }
220
221    if !memory_data.is_empty() {
222        memory_data.sort_by_key(|(qubits, _, _)| *qubits);
223
224        println!("   Memory scaling by qubit count:");
225        for (qubits, memory, name) in memory_data {
226            println!(
227                "     - {} qubits ({}): {:.1} MB",
228                qubits,
229                name,
230                memory as f64 / 1024.0 / 1024.0
231            );
232        }
233        println!("     - Expected scaling: O(2^n) for statevector simulation");
234        println!();
235    }
236
237    // Print recommendations
238    println!("   Recommendations:");
239    println!("     - Use statevector backend for circuits ≤ 12 qubits");
240    println!("     - Use MPS backend for larger circuits with limited entanglement");
241    println!("     - Consider circuit optimization for memory-constrained environments");
242}
243
244fn extract_qubit_count(benchmark_name: &str) -> usize {
245    // Extract number from strings like "vqe_4q_statevector", "qaoa_6q_mps", etc.
246    for part in benchmark_name.split('_') {
247        if part.ends_with('q') {
248            if let Ok(num) = part.trim_end_matches('q').parse::<usize>() {
249                return num;
250            }
251        }
252    }
253    0 // Default if not found
254}
255
256// Additional analysis functions
257fn analyze_backend_performance(results: &BenchmarkResults) {
258    println!("   Backend Performance Comparison:");
259    println!("   ==============================");
260
261    // Group results by backend type
262    let mut backend_performance = std::collections::HashMap::new();
263
264    for (name, summary) in results.summaries() {
265        let backend_type = extract_backend_type(name);
266        backend_performance
267            .entry(backend_type)
268            .or_insert_with(Vec::new)
269            .push(summary.mean_time.as_secs_f64());
270    }
271
272    for (backend, times) in backend_performance {
273        let avg_time = times.iter().sum::<f64>() / times.len() as f64;
274        println!("     - {backend} backend: {avg_time:.3}s average");
275    }
276}
Source

pub fn results(&self) -> &HashMap<String, Vec<BenchmarkRunResult>>

Get results

Source

pub fn metadata(&self) -> &BenchmarkMetadata

Get metadata

Trait Implementations§

Source§

impl Clone for BenchmarkResults

Source§

fn clone(&self) -> BenchmarkResults

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BenchmarkResults

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V