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: StringName of the operation
parameters: HashMap<String, String>Parameters used in the benchmark
duration: DurationTotal execution time
memory_used: Option<usize>Memory usage in bytes (if measured)
samples: usizeNumber of samples processed
features: usizeNumber of features
throughput: f64Throughput (samples per second)
success: boolSuccess/failure status
error: Option<String>Error message if failed
Implementations§
Source§impl BenchmarkResult
impl BenchmarkResult
Sourcepub fn new(operation: String, parameters: HashMap<String, String>) -> Self
pub fn new(operation: String, parameters: HashMap<String, String>) -> Self
Create a new benchmark result
Sourcepub fn success(
self,
duration: Duration,
samples: usize,
features: usize,
) -> Self
pub fn success( self, duration: Duration, samples: usize, features: usize, ) -> Self
Mark the benchmark as successful with timing information
Sourcepub fn with_memory(self, memoryused: usize) -> Self
pub fn with_memory(self, memoryused: usize) -> Self
Set memory usage
Sourcepub fn formatted_duration(&self) -> String
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
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}Sourcepub fn formatted_throughput(&self) -> String
pub fn formatted_throughput(&self) -> String
Get formatted throughput string
Sourcepub fn formatted_memory(&self) -> String
pub fn formatted_memory(&self) -> String
Get formatted memory usage string
Trait Implementations§
Source§impl Clone for BenchmarkResult
impl Clone for BenchmarkResult
Source§fn clone(&self) -> BenchmarkResult
fn clone(&self) -> BenchmarkResult
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 BenchmarkResult
impl RefUnwindSafe for BenchmarkResult
impl Send for BenchmarkResult
impl Sync for BenchmarkResult
impl Unpin for BenchmarkResult
impl UnwindSafe for BenchmarkResult
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
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
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
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.