use criterion::{criterion_group, criterion_main, Criterion}; use quantum_bridge_mcp::executor::{CanExecute, LocalSimulator}; use quantum_bridge_mcp::types::{CircuitSource, ShotCount}; const BELL_CIRCUIT: &str = r#"OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; bit[2] c; h q[0]; cx q[0], q[1]; c = measure q;"#; fn make_h_circuit(n_qubits: usize, n_shots: u32) -> (CircuitSource, ShotCount) { let gates: String = (0..n_qubits).map(|i| format!("h q[{i}];\n")).collect(); let circuit = format!( "OPENQASM 3.0;\ninclude \"stdgates.inc\";\nqubit[{n_qubits}] q;\nbit[{n_qubits}] c;\n{gates}c = measure q;\n" ); (CircuitSource(circuit), ShotCount(n_shots)) } fn bench_bell_1024_shots(c: &mut Criterion) { let sim = LocalSimulator::new(); c.bench_function("bell_1024_shots", |b| { b.iter(|| { sim.run( &CircuitSource(BELL_CIRCUIT.to_string()), ShotCount(1024), false, ) .unwrap() }) }); } fn bench_10_qubits_1k_shots(c: &mut Criterion) { let sim = LocalSimulator::new(); let (circuit, shots) = make_h_circuit(10, 1_000); c.bench_function("10_qubits_1k_shots", |b| { b.iter(|| sim.run(&circuit, shots, false).unwrap()) }); } fn bench_20_qubits_100_shots(c: &mut Criterion) { let sim = LocalSimulator::new(); let (circuit, shots) = make_h_circuit(20, 100); c.bench_function("20_qubits_100_shots", |b| { b.iter(|| sim.run(&circuit, shots, false).unwrap()) }); } criterion_group!( benches, bench_bell_1024_shots, bench_10_qubits_1k_shots, bench_20_qubits_100_shots, ); criterion_main!(benches);