pub struct BenchmarkAnalysis {
pub name: String,
pub count: usize,
pub min: u64,
pub max: u64,
pub mean: u64,
pub p50: u64,
pub p95: u64,
pub p99: u64,
pub p999: u64,
pub std_dev: f64,
}Fields§
§name: String§count: usize§min: u64§max: u64§mean: u64§p50: u64§p95: u64§p99: u64§p999: u64§std_dev: f64Implementations§
Source§impl BenchmarkAnalysis
impl BenchmarkAnalysis
pub fn empty(name: String) -> Self
pub fn summary(&self) -> String
Sourcepub fn meets_target(&self, target_p99_ns: u64) -> bool
pub fn meets_target(&self, target_p99_ns: u64) -> bool
Examples found in repository?
examples/simple_benchmark_example.rs (line 45)
5fn main() {
6 quick_calibrate_tsc_frequency();
7
8 #[cfg(target_arch = "aarch64")]
9 {
10 let resolution_ns = 1_000_000_000u64 / 24_000_000u64;
11 println!("Note: ARM64 timing resolution is ~{}ns. Very fast operations may show limited precision.\n", resolution_ns);
12 }
13
14 println!("=== Simple Arithmetic Benchmark ===");
15 SimpleBench::new("arithmetic")
16 .bench(10000, || {
17 let a = 42u64;
18 let b = 37u64;
19 a.wrapping_add(b).wrapping_mul(2)
20 })
21 .report();
22
23 println!("\n=== Vector Allocation Benchmark ===");
24 SimpleBench::new("vec_allocation")
25 .bench(1000, || {
26 let vec: Vec<u64> = Vec::with_capacity(100);
27 drop(vec);
28 })
29 .report();
30
31 println!("\n=== Function Call Overhead ===");
32 fn dummy_function(x: u64) -> u64 {
33 x.wrapping_add(1)
34 }
35
36 SimpleBench::new("function_call")
37 .bench(5000, || dummy_function(42))
38 .report();
39
40 println!("\n=== Custom Analysis Example ===");
41 let analysis = SimpleBench::new("analysis_example")
42 .bench(1000, || std::hint::black_box(42))
43 .analyze();
44
45 if analysis.meets_target(100) {
46 println!("✓ Performance target met! P99: {}ns", analysis.p99);
47 } else {
48 println!("✗ Performance target missed. P99: {}ns", analysis.p99);
49 }
50
51 println!("\n=== Implementation Comparison ===");
52
53 let old_analysis = SimpleBench::new("old_impl")
54 .bench(1000, || {
55 for _ in 0..10 {
56 std::hint::black_box(42);
57 }
58 })
59 .analyze();
60
61 let new_analysis = SimpleBench::new("new_impl")
62 .bench(1000, || {
63 std::hint::black_box(42);
64 })
65 .analyze();
66
67 println!("Old: {}ns P99, New: {}ns P99", old_analysis.p99, new_analysis.p99);
68
69 if new_analysis.mean == 0 {
70 println!("Improvement: Operation too fast to measure precisely (< {}ns resolution)",
71 1_000_000_000u64 / 24_000_000u64);
72 } else {
73 let improvement = (old_analysis.mean as f64 / new_analysis.mean as f64 - 1.0) * 100.0;
74 println!("Improvement: {:.1}% faster", improvement);
75 }
76}More examples
examples/custom_benchmark.rs (line 90)
26fn main() {
27 println!("🎯 Custom Benchmark Examples\n");
28
29 quick_calibrate_tsc_frequency();
30
31 // Benchmark 1: Simple arithmetic
32 println!("=== Arithmetic Operations ===");
33 SimpleBench::new("fast_multiply")
34 .bench(10000, || fast_multiply(12345, 67890))
35 .report();
36
37 // Benchmark 2: Recursive function (warning: slow!)
38 println!("\n=== Recursive Function ===");
39 SimpleBench::new("fibonacci_20")
40 .bench(100, || fibonacci(20)) // Only 100 iterations - fibonacci is slow!
41 .report();
42
43 // Benchmark 3: String operations
44 println!("\n=== String Operations ===");
45 SimpleBench::new("string_ops")
46 .bench(1000, || string_operations())
47 .report();
48
49 // Benchmark 4: Compare two implementations
50 println!("\n=== Implementation Comparison ===");
51 let method_a = SimpleBench::new("method_a")
52 .bench(5000, || {
53 // Method A: Manual loop
54 let mut sum = 0u64;
55 for i in 0..100 {
56 sum += i;
57 }
58 sum
59 })
60 .analyze();
61
62 let method_b = SimpleBench::new("method_b")
63 .bench(5000, || {
64 // Method B: Iterator
65 (0..100u64).sum::<u64>()
66 })
67 .analyze();
68
69 println!("Method A (manual loop): {}ns P99", method_a.p99);
70 println!("Method B (iterator): {}ns P99", method_b.p99);
71
72 if method_b.p99 < method_a.p99 {
73 let improvement = (method_a.p99 as f64 / method_b.p99 as f64 - 1.0) * 100.0;
74 println!("Iterator is {:.1}% faster!", improvement);
75 } else {
76 let degradation = (method_b.p99 as f64 / method_a.p99 as f64 - 1.0) * 100.0;
77 println!("Manual loop is {:.1}% faster!", degradation);
78 }
79
80 // Benchmark 5: Performance validation
81 println!("\n=== Performance Validation ===");
82 let critical_path = SimpleBench::new("critical_operation")
83 .bench(1000, || {
84 // Simulate a critical operation
85 std::hint::black_box(42 * 37 + 15)
86 })
87 .analyze();
88
89 const TARGET_P99_NS: u64 = 100;
90 if critical_path.meets_target(TARGET_P99_NS) {
91 println!("✅ Performance target met! P99: {}ns (target: <{}ns)",
92 critical_path.p99, TARGET_P99_NS);
93 } else {
94 println!("❌ Performance target missed! P99: {}ns (target: <{}ns)",
95 critical_path.p99, TARGET_P99_NS);
96 }
97}Trait Implementations§
Source§impl Clone for BenchmarkAnalysis
impl Clone for BenchmarkAnalysis
Source§fn clone(&self) -> BenchmarkAnalysis
fn clone(&self) -> BenchmarkAnalysis
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 BenchmarkAnalysis
impl RefUnwindSafe for BenchmarkAnalysis
impl Send for BenchmarkAnalysis
impl Sync for BenchmarkAnalysis
impl Unpin for BenchmarkAnalysis
impl UnwindSafe for BenchmarkAnalysis
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 more