BenchmarkResult

Struct BenchmarkResult 

Source
pub struct BenchmarkResult {
    pub operation: String,
    pub parameters: HashMap<String, String>,
    pub duration: Duration,
    pub memory_used: Option<usize>,
    pub samples: usize,
    pub features: usize,
    pub throughput: f64,
    pub success: bool,
    pub error: Option<String>,
}
Expand description

Benchmark result for a single operation

Fields§

§operation: String

Name of the operation

§parameters: HashMap<String, String>

Parameters used in the benchmark

§duration: Duration

Total execution time

§memory_used: Option<usize>

Memory usage in bytes (if measured)

§samples: usize

Number of samples processed

§features: usize

Number of features

§throughput: f64

Throughput (samples per second)

§success: bool

Success/failure status

§error: Option<String>

Error message if failed

Implementations§

Source§

impl BenchmarkResult

Source

pub fn new(operation: String, parameters: HashMap<String, String>) -> Self

Create a new benchmark result

Source

pub fn success( self, duration: Duration, samples: usize, features: usize, ) -> Self

Mark the benchmark as successful with timing information

Source

pub fn failure(self, error: String) -> Self

Mark the benchmark as failed with error message

Source

pub fn with_memory(self, memoryused: usize) -> Self

Set memory usage

Source

pub fn formatted_duration(&self) -> String

Get formatted duration string

Examples found in repository?
examples/scikit_learn_benchmark.rs (line 80)
56fn analyze_toy_dataset_performance(suites: &[BenchmarkSuite]) {
57    if let Some(toy_suite) = suites.iter().find(|s| s.name == "Toy Datasets") {
58        println!("\n📊 TOY DATASET LOADING ANALYSIS");
59        println!("{}", "-".repeat(40));
60
61        let mut total_loading_time = Duration::ZERO;
62        let mut total_samples = 0;
63        let mut fastestdataset = ("", Duration::MAX);
64        let mut slowestdataset = ("", Duration::ZERO);
65
66        for result in toy_suite.successful_results() {
67            total_loading_time += result.duration;
68            total_samples += result.samples;
69
70            if result.duration < fastestdataset.1 {
71                fastestdataset = (&result.operation, result.duration);
72            }
73            if result.duration > slowestdataset.1 {
74                slowestdataset = (&result.operation, result.duration);
75            }
76
77            println!(
78                "  {}: {} ({} samples, {:.1} samples/s)",
79                result.operation.replace("load_", ""),
80                result.formatted_duration(),
81                result.samples,
82                result.throughput
83            );
84        }
85
86        println!("\n  Summary:");
87        println!(
88            "    Total loading time: {:.2}s",
89            total_loading_time.as_secs_f64()
90        );
91        println!("    Total samples loaded: {total_samples}");
92        println!(
93            "    Average throughput: {:.1} samples/s",
94            total_samples as f64 / total_loading_time.as_secs_f64()
95        );
96        println!(
97            "    Fastest: {} ({})",
98            fastestdataset.0,
99            format_duration(fastestdataset.1)
100        );
101        println!(
102            "    Slowest: {} ({})",
103            slowestdataset.0,
104            format_duration(slowestdataset.1)
105        );
106    }
107}
More examples
Hide additional examples
examples/real_world_datasets.rs (line 406)
354fn demonstrate_performance_comparison() -> Result<(), Box<dyn std::error::Error>> {
355    println!("⚡ PERFORMANCE COMPARISON");
356    println!("{}", "-".repeat(40));
357
358    let runner = BenchmarkRunner::new().with_iterations(3).with_warmup(1);
359
360    // Benchmark real-world dataset loading
361    println!("Benchmarking real-world dataset operations...");
362
363    // Titanic loading benchmark
364    let titanic_params = HashMap::from([("dataset".to_string(), "titanic".to_string())]);
365    let titanic_result =
366        runner.run_benchmark("load_titanic", titanic_params, || match load_titanic() {
367            Ok(dataset) => Ok((dataset.n_samples(), dataset.n_features())),
368            Err(e) => Err(format!("Failed to load Titanic: {e}")),
369        });
370
371    // California Housing loading benchmark
372    let housing_params = HashMap::from([("dataset".to_string(), "california_housing".to_string())]);
373    let housing_result = runner.run_benchmark("load_california_housing", housing_params, || {
374        match load_california_housing() {
375            Ok(dataset) => Ok((dataset.n_samples(), dataset.n_features())),
376            Err(e) => Err(format!("Failed to load California Housing: {e}")),
377        }
378    });
379
380    // Heart Disease loading benchmark
381    let heart_params = HashMap::from([("dataset".to_string(), "heart_disease".to_string())]);
382    let heart_result =
383        runner.run_benchmark(
384            "load_heart_disease",
385            heart_params,
386            || match load_heart_disease() {
387                Ok(dataset) => Ok((dataset.n_samples(), dataset.n_features())),
388                Err(e) => Err(format!("Failed to load Heart Disease: {e}")),
389            },
390        );
391
392    // Display results
393    println!("\nReal-world dataset loading performance:");
394
395    let results = vec![
396        ("Titanic", &titanic_result),
397        ("California Housing", &housing_result),
398        ("Heart Disease", &heart_result),
399    ];
400
401    for (name, result) in results {
402        if result.success {
403            println!(
404                "  {}: {} ({} samples, {} features, {:.1} samples/s)",
405                name,
406                result.formatted_duration(),
407                result.samples,
408                result.features,
409                result.throughput
410            );
411        } else {
412            println!(
413                "  {}: Failed - {}",
414                name,
415                result
416                    .error
417                    .as_ref()
418                    .unwrap_or(&"Unknown error".to_string())
419            );
420        }
421    }
422
423    // Memory usage estimation
424    let total_samples = titanic_result.samples + housing_result.samples + heart_result.samples;
425    let total_features = titanic_result.features + housing_result.features + heart_result.features;
426    let estimated_memory_mb = (total_samples * total_features * 8) as f64 / (1024.0 * 1024.0);
427
428    println!("\nMemory usage estimate:");
429    println!("  Total samples: {total_samples}");
430    println!("  Total features: {total_features}");
431    println!("  Estimated memory: {estimated_memory_mb:.1} MB");
432
433    // Performance recommendations
434    println!("\nPerformance recommendations:");
435    if estimated_memory_mb > 100.0 {
436        println!("  • Consider using streaming for large datasets");
437        println!("  • Enable caching for frequently accessed datasets");
438    }
439    println!("  • Use train/test splitting to reduce memory usage");
440    println!("  • Apply feature selection to reduce dimensionality");
441
442    println!();
443    Ok(())
444}
Source

pub fn formatted_throughput(&self) -> String

Get formatted throughput string

Source

pub fn formatted_memory(&self) -> String

Get formatted memory usage string

Trait Implementations§

Source§

impl Clone for BenchmarkResult

Source§

fn clone(&self) -> BenchmarkResult

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 BenchmarkResult

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