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
impl PerformanceMetrics
pub fn new() -> Self
Sourcepub fn record(
&mut self,
operation: &str,
duration: Duration,
memory_kb: usize,
throughput_mbps: f64,
)
pub fn record( &mut self, operation: &str, duration: Duration, memory_kb: usize, throughput_mbps: f64, )
Record a performance metric
Sourcepub fn avg_time(&self, operation: &str) -> Option<Duration>
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}Sourcepub fn avg_throughput(&self, operation: &str) -> Option<f64>
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
impl Clone for PerformanceMetrics
Source§fn clone(&self) -> PerformanceMetrics
fn clone(&self) -> PerformanceMetrics
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 moreSource§impl Debug for PerformanceMetrics
impl Debug for PerformanceMetrics
Source§impl Default for PerformanceMetrics
impl Default for PerformanceMetrics
Source§fn default() -> PerformanceMetrics
fn default() -> PerformanceMetrics
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for PerformanceMetrics
impl RefUnwindSafe for PerformanceMetrics
impl Send for PerformanceMetrics
impl Sync for PerformanceMetrics
impl Unpin for PerformanceMetrics
impl UnwindSafe for PerformanceMetrics
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