BenchmarkAnalysis

Struct BenchmarkAnalysis 

Source
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: f64

Implementations§

Source§

impl BenchmarkAnalysis

Source

pub fn empty(name: String) -> Self

Source

pub fn summary(&self) -> String

Source

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
Hide additional 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

Source§

fn clone(&self) -> BenchmarkAnalysis

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 BenchmarkAnalysis

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> 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.