Skip to main content

PerformanceMetrics

Struct PerformanceMetrics 

Source
pub struct PerformanceMetrics {
    pub operation_times: HashMap<String, Vec<Duration>>,
    pub memory_usage: HashMap<String, Vec<usize>>,
    pub throughput: HashMap<String, Vec<f64>>,
}
Expand description

Performance metrics collector shared across tests

Fields§

§operation_times: HashMap<String, Vec<Duration>>§memory_usage: HashMap<String, Vec<usize>>§throughput: HashMap<String, Vec<f64>>

Implementations§

Source§

impl PerformanceMetrics

Source

pub fn new() -> Self

Source

pub fn record( &mut self, operation: &str, duration: Duration, memory_kb: usize, throughput_mbps: f64, )

Record a performance metric

Source

pub fn avg_time(&self, operation: &str) -> Option<Duration>

Get average time for an operation

Examples found in repository?
examples/test_harness.rs (line 73)
7fn main() {
8    println!("=== Embeddenator TestKit - Test Harness ===\n");
9
10    // Create test harness (automatically manages temp directory)
11    println!("1. Creating test harness...");
12    let harness = TestHarness::new();
13    println!("   Temp directory: {:?}", harness.temp_dir());
14
15    // Create a simple test file
16    println!("\n2. Creating test file...");
17    let file_path = harness.create_file("test.txt", b"Hello, World!");
18    println!("   Created: {:?}", file_path);
19    println!("   Exists: {}", file_path.exists());
20
21    // Create a test dataset
22    println!("\n3. Creating test dataset (5MB)...");
23    let dataset_path = harness.create_dataset(5);
24    println!("   Dataset directory: {:?}", dataset_path);
25
26    // List files in dataset
27    let files: Vec<_> = std::fs::read_dir(&dataset_path)
28        .unwrap()
29        .filter_map(|e| e.ok())
30        .collect();
31    println!("   Files created: {}", files.len());
32
33    if let Some(first_file) = files.first() {
34        let metadata = first_file.metadata().unwrap();
35        println!("   First file size: {} bytes", metadata.len());
36    }
37
38    // Create large file with specific pattern
39    println!("\n4. Creating large file with pattern...");
40    let large_file = harness.create_large_file(
41        "sequential.bin",
42        10, // 10MB
43        TestDataPattern::Sequential,
44    );
45    let metadata = std::fs::metadata(&large_file).unwrap();
46    println!("   Created: {:?}", large_file);
47    println!(
48        "   Size: {} bytes ({} MB)",
49        metadata.len(),
50        metadata.len() / 1024 / 1024
51    );
52
53    // Create directory structure
54    println!("\n5. Creating directory structure...");
55    let dir_structure = harness.create_directory_structure("project");
56    println!("   Base: {:?}", dir_structure);
57    println!("   Contains dir1: {}", dir_structure.join("dir1").exists());
58    println!(
59        "   Contains dir2/nested: {}",
60        dir_structure.join("dir2/nested").exists()
61    );
62
63    // Record metrics
64    println!("\n6. Recording performance metrics...");
65    harness.record_metric(
66        "dataset_creation",
67        std::time::Duration::from_secs(1),
68        5120, // 5MB in KB
69        5.0,  // 5 MB/s
70    );
71
72    let metrics = harness.metrics();
73    if let Some(avg_time) = metrics.avg_time("dataset_creation") {
74        println!("   Average time: {:?}", avg_time);
75    }
76    if let Some(avg_throughput) = metrics.avg_throughput("dataset_creation") {
77        println!("   Average throughput: {:.2} MB/s", avg_throughput);
78    }
79
80    println!("\n✅ Test harness example complete!");
81    println!("   (Temp directory will be automatically cleaned up)");
82}
Source

pub fn avg_throughput(&self, operation: &str) -> Option<f64>

Get average throughput for an operation

Examples found in repository?
examples/test_harness.rs (line 76)
7fn main() {
8    println!("=== Embeddenator TestKit - Test Harness ===\n");
9
10    // Create test harness (automatically manages temp directory)
11    println!("1. Creating test harness...");
12    let harness = TestHarness::new();
13    println!("   Temp directory: {:?}", harness.temp_dir());
14
15    // Create a simple test file
16    println!("\n2. Creating test file...");
17    let file_path = harness.create_file("test.txt", b"Hello, World!");
18    println!("   Created: {:?}", file_path);
19    println!("   Exists: {}", file_path.exists());
20
21    // Create a test dataset
22    println!("\n3. Creating test dataset (5MB)...");
23    let dataset_path = harness.create_dataset(5);
24    println!("   Dataset directory: {:?}", dataset_path);
25
26    // List files in dataset
27    let files: Vec<_> = std::fs::read_dir(&dataset_path)
28        .unwrap()
29        .filter_map(|e| e.ok())
30        .collect();
31    println!("   Files created: {}", files.len());
32
33    if let Some(first_file) = files.first() {
34        let metadata = first_file.metadata().unwrap();
35        println!("   First file size: {} bytes", metadata.len());
36    }
37
38    // Create large file with specific pattern
39    println!("\n4. Creating large file with pattern...");
40    let large_file = harness.create_large_file(
41        "sequential.bin",
42        10, // 10MB
43        TestDataPattern::Sequential,
44    );
45    let metadata = std::fs::metadata(&large_file).unwrap();
46    println!("   Created: {:?}", large_file);
47    println!(
48        "   Size: {} bytes ({} MB)",
49        metadata.len(),
50        metadata.len() / 1024 / 1024
51    );
52
53    // Create directory structure
54    println!("\n5. Creating directory structure...");
55    let dir_structure = harness.create_directory_structure("project");
56    println!("   Base: {:?}", dir_structure);
57    println!("   Contains dir1: {}", dir_structure.join("dir1").exists());
58    println!(
59        "   Contains dir2/nested: {}",
60        dir_structure.join("dir2/nested").exists()
61    );
62
63    // Record metrics
64    println!("\n6. Recording performance metrics...");
65    harness.record_metric(
66        "dataset_creation",
67        std::time::Duration::from_secs(1),
68        5120, // 5MB in KB
69        5.0,  // 5 MB/s
70    );
71
72    let metrics = harness.metrics();
73    if let Some(avg_time) = metrics.avg_time("dataset_creation") {
74        println!("   Average time: {:?}", avg_time);
75    }
76    if let Some(avg_throughput) = metrics.avg_throughput("dataset_creation") {
77        println!("   Average throughput: {:.2} MB/s", avg_throughput);
78    }
79
80    println!("\n✅ Test harness example complete!");
81    println!("   (Temp directory will be automatically cleaned up)");
82}

Trait Implementations§

Source§

impl Clone for PerformanceMetrics

Source§

fn clone(&self) -> PerformanceMetrics

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 PerformanceMetrics

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PerformanceMetrics

Source§

fn default() -> PerformanceMetrics

Returns the “default value” for a type. 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> Same for T

Source§

type Output = T

Should always be Self
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