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

Source§

impl<T> Ungil for T
where T: Send,