oxigdal-bench 0.1.7

Comprehensive performance profiling and benchmarking suite for OxiGDAL
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
//! ML inference benchmark scenarios.
//!
//! This module provides benchmark scenarios for ML operations including:
//! - ONNX model inference
//! - Batch processing performance
//! - Preprocessing overhead
//! - Postprocessing performance
//! - End-to-end inference pipeline

use crate::error::{BenchError, Result};
use crate::scenarios::BenchmarkScenario;
use std::path::PathBuf;

/// ML task types.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MlTask {
    /// Image classification.
    Classification,
    /// Object detection.
    Detection,
    /// Semantic segmentation.
    Segmentation,
    /// Instance segmentation.
    InstanceSegmentation,
}

/// ONNX inference benchmark scenario.
pub struct OnnxInferenceScenario {
    model_path: PathBuf,
    input_shape: Vec<usize>,
    batch_size: usize,
    task_type: MlTask,
    warmup_iterations: usize,
    benchmark_iterations: usize,
}

impl OnnxInferenceScenario {
    /// Creates a new ONNX inference benchmark scenario.
    pub fn new<P>(model_path: P, input_shape: Vec<usize>) -> Self
    where
        P: Into<PathBuf>,
    {
        Self {
            model_path: model_path.into(),
            input_shape,
            batch_size: 1,
            task_type: MlTask::Classification,
            warmup_iterations: 10,
            benchmark_iterations: 100,
        }
    }

    /// Sets the batch size.
    pub fn with_batch_size(mut self, batch_size: usize) -> Self {
        self.batch_size = batch_size;
        self
    }

    /// Sets the task type.
    pub fn with_task_type(mut self, task_type: MlTask) -> Self {
        self.task_type = task_type;
        self
    }

    /// Sets the warmup iterations.
    pub fn with_warmup_iterations(mut self, iterations: usize) -> Self {
        self.warmup_iterations = iterations;
        self
    }

    /// Sets the benchmark iterations.
    pub fn with_benchmark_iterations(mut self, iterations: usize) -> Self {
        self.benchmark_iterations = iterations;
        self
    }
}

impl BenchmarkScenario for OnnxInferenceScenario {
    fn name(&self) -> &str {
        "onnx_inference"
    }

    fn description(&self) -> &str {
        "Benchmark ONNX model inference performance"
    }

    fn setup(&mut self) -> Result<()> {
        if !self.model_path.exists() {
            return Err(BenchError::scenario_failed(
                self.name(),
                format!("Model file does not exist: {}", self.model_path.display()),
            ));
        }

        if self.input_shape.is_empty() {
            return Err(BenchError::InvalidConfiguration(
                "Input shape cannot be empty".to_string(),
            ));
        }

        Ok(())
    }

    fn execute(&mut self) -> Result<()> {
        #[cfg(feature = "ml")]
        {
            // Simulate ONNX inference with synthetic tensors
            let input_size: usize = self.input_shape.iter().product();
            let input_data: Vec<f32> = (0..input_size * self.batch_size)
                .map(|i| (i as f32 * 0.001_f32).sin())
                .collect();

            // Warmup iterations: simulate lightweight forward pass
            for _ in 0..self.warmup_iterations {
                let _out: Vec<f32> = input_data
                    .iter()
                    .map(|&x| 1.0_f32 / (1.0_f32 + (-x).exp())) // sigmoid activation
                    .collect();
            }

            // Benchmark iterations: simulate full matmul-like operation
            let hidden_size = 256usize;
            for _ in 0..self.benchmark_iterations {
                let _out: Vec<f32> = (0..hidden_size)
                    .map(|j| {
                        input_data.iter().enumerate().fold(0.0_f32, |acc, (i, &x)| {
                            acc + x * ((i + j) as f32 * 0.001_f32).cos()
                        })
                    })
                    .collect();
            }
        }

        #[cfg(not(feature = "ml"))]
        {
            return Err(BenchError::missing_dependency("oxigdal-ml", "ml"));
        }

        Ok(())
    }

    fn teardown(&mut self) -> Result<()> {
        Ok(())
    }
}

/// Batch processing benchmark scenario.
pub struct BatchProcessingScenario {
    model_path: PathBuf,
    input_dir: PathBuf,
    batch_sizes: Vec<usize>,
    task_type: MlTask,
}

impl BatchProcessingScenario {
    /// Creates a new batch processing benchmark scenario.
    pub fn new<P1, P2>(model_path: P1, input_dir: P2) -> Self
    where
        P1: Into<PathBuf>,
        P2: Into<PathBuf>,
    {
        Self {
            model_path: model_path.into(),
            input_dir: input_dir.into(),
            batch_sizes: vec![1, 4, 8, 16, 32],
            task_type: MlTask::Classification,
        }
    }

    /// Sets the batch sizes to benchmark.
    pub fn with_batch_sizes(mut self, sizes: Vec<usize>) -> Self {
        self.batch_sizes = sizes;
        self
    }

    /// Sets the task type.
    pub fn with_task_type(mut self, task_type: MlTask) -> Self {
        self.task_type = task_type;
        self
    }
}

impl BenchmarkScenario for BatchProcessingScenario {
    fn name(&self) -> &str {
        "batch_processing"
    }

    fn description(&self) -> &str {
        "Benchmark batch processing performance with different batch sizes"
    }

    fn setup(&mut self) -> Result<()> {
        if !self.model_path.exists() {
            return Err(BenchError::scenario_failed(
                self.name(),
                format!("Model file does not exist: {}", self.model_path.display()),
            ));
        }

        if !self.input_dir.exists() {
            return Err(BenchError::scenario_failed(
                self.name(),
                format!(
                    "Input directory does not exist: {}",
                    self.input_dir.display()
                ),
            ));
        }

        Ok(())
    }

    fn execute(&mut self) -> Result<()> {
        #[cfg(feature = "ml")]
        {
            // Simulate batch processing with varying batch sizes
            // Generate synthetic image data (3-channel, 224x224 = 150528 floats per image)
            let image_size = 3 * 224 * 224usize;
            let total_images = 32usize;
            let images: Vec<Vec<f32>> = (0..total_images)
                .map(|img_idx| {
                    (0..image_size)
                        .map(|i| ((img_idx + i) as f32 * 0.001_f32).sin())
                        .collect()
                })
                .collect();

            for &batch_size in &self.batch_sizes {
                for chunk in images.chunks(batch_size) {
                    // Flatten batch into contiguous tensor
                    let batch_tensor: Vec<f32> =
                        chunk.iter().flat_map(|img| img.iter().copied()).collect();
                    // Simulate softmax over 1000 classes for each image in batch
                    let logits: Vec<f32> = (0..chunk.len() * 1000)
                        .map(|i| batch_tensor[i % batch_tensor.len()])
                        .collect();
                    let _max_class: usize = logits
                        .iter()
                        .enumerate()
                        .max_by(|(_, a), (_, b)| {
                            a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal)
                        })
                        .map(|(i, _)| i)
                        .unwrap_or(0);
                }
            }
        }

        #[cfg(not(feature = "ml"))]
        {
            return Err(BenchError::missing_dependency("oxigdal-ml", "ml"));
        }

        Ok(())
    }

    fn teardown(&mut self) -> Result<()> {
        Ok(())
    }
}

/// Preprocessing benchmark scenario.
pub struct PreprocessingScenario {
    input_dir: PathBuf,
    preprocessing_steps: Vec<PreprocessingStep>,
    image_count: usize,
}

/// Preprocessing steps.
#[derive(Debug, Clone, Copy)]
pub enum PreprocessingStep {
    /// Resize to target dimensions.
    Resize,
    /// Normalize pixel values.
    Normalize,
    /// Convert color space.
    ColorConversion,
    /// Apply data augmentation.
    Augmentation,
}

impl PreprocessingScenario {
    /// Creates a new preprocessing benchmark scenario.
    pub fn new<P>(input_dir: P) -> Self
    where
        P: Into<PathBuf>,
    {
        Self {
            input_dir: input_dir.into(),
            preprocessing_steps: vec![PreprocessingStep::Resize, PreprocessingStep::Normalize],
            image_count: 100,
        }
    }

    /// Sets the preprocessing steps.
    pub fn with_steps(mut self, steps: Vec<PreprocessingStep>) -> Self {
        self.preprocessing_steps = steps;
        self
    }

    /// Sets the number of images to process.
    pub fn with_image_count(mut self, count: usize) -> Self {
        self.image_count = count;
        self
    }
}

impl BenchmarkScenario for PreprocessingScenario {
    fn name(&self) -> &str {
        "preprocessing"
    }

    fn description(&self) -> &str {
        "Benchmark image preprocessing performance"
    }

    fn setup(&mut self) -> Result<()> {
        if !self.input_dir.exists() {
            return Err(BenchError::scenario_failed(
                self.name(),
                format!(
                    "Input directory does not exist: {}",
                    self.input_dir.display()
                ),
            ));
        }

        Ok(())
    }

    fn execute(&mut self) -> Result<()> {
        #[cfg(feature = "ml")]
        {
            // Simulate image preprocessing pipeline
            let image_width = 640usize;
            let image_height = 480usize;
            let channels = 3usize;
            for img_idx in 0..self.image_count {
                let raw: Vec<u8> = (0..image_width * image_height * channels)
                    .map(|i| ((img_idx * 7 + i) % 256) as u8)
                    .collect();
                let mut processed: Vec<f32> = raw.iter().map(|&b| b as f32).collect();
                for step in &self.preprocessing_steps {
                    processed = match step {
                        PreprocessingStep::Resize => {
                            // Bilinear downsample to 224x224x3
                            let target = 224usize;
                            (0..target * target * channels)
                                .map(|i| {
                                    let c = i % channels;
                                    let px = (i / channels) % target;
                                    let py = i / channels / target;
                                    let src_x = px * image_width / target;
                                    let src_y = py * image_height / target;
                                    processed[(src_y * image_width + src_x) * channels + c]
                                })
                                .collect()
                        }
                        PreprocessingStep::Normalize => {
                            // ImageNet normalization: (x/255 - mean) / std
                            let mean = [0.485_f32, 0.456, 0.406];
                            let std_vals = [0.229_f32, 0.224, 0.225];
                            processed
                                .iter()
                                .enumerate()
                                .map(|(i, &v)| {
                                    let c = i % channels;
                                    (v / 255.0 - mean[c]) / std_vals[c]
                                })
                                .collect()
                        }
                        PreprocessingStep::ColorConversion => {
                            // RGB → BGR swap
                            let mut bgr = processed.clone();
                            for px in 0..(bgr.len() / channels) {
                                bgr.swap(px * channels, px * channels + 2);
                            }
                            bgr
                        }
                        PreprocessingStep::Augmentation => {
                            // Horizontal flip
                            let w = if processed.len() > channels {
                                processed.len() / channels
                            } else {
                                1
                            };
                            let mut flipped = processed.clone();
                            for row in 0..(flipped.len() / channels / w.max(1)) {
                                for col in 0..(w / 2) {
                                    for c in 0..channels {
                                        let a = (row * w + col) * channels + c;
                                        let b_idx = (row * w + (w - 1 - col)) * channels + c;
                                        if a < flipped.len() && b_idx < flipped.len() {
                                            flipped.swap(a, b_idx);
                                        }
                                    }
                                }
                            }
                            flipped
                        }
                    };
                }
                let _ = processed;
            }
        }

        #[cfg(not(feature = "ml"))]
        {
            return Err(BenchError::missing_dependency("oxigdal-ml", "ml"));
        }

        Ok(())
    }

    fn teardown(&mut self) -> Result<()> {
        Ok(())
    }
}

/// Postprocessing benchmark scenario.
pub struct PostprocessingScenario {
    #[allow(dead_code)]
    task_type: MlTask,
    result_count: usize,
    nms_threshold: f32,
}

impl PostprocessingScenario {
    /// Creates a new postprocessing benchmark scenario.
    pub fn new(task_type: MlTask) -> Self {
        Self {
            task_type,
            result_count: 1000,
            nms_threshold: 0.5,
        }
    }

    /// Sets the number of results to process.
    pub fn with_result_count(mut self, count: usize) -> Self {
        self.result_count = count;
        self
    }

    /// Sets the NMS threshold for detection tasks.
    pub fn with_nms_threshold(mut self, threshold: f32) -> Self {
        self.nms_threshold = threshold;
        self
    }
}

impl BenchmarkScenario for PostprocessingScenario {
    fn name(&self) -> &str {
        "postprocessing"
    }

    fn description(&self) -> &str {
        "Benchmark postprocessing performance (NMS, etc.)"
    }

    fn setup(&mut self) -> Result<()> {
        Ok(())
    }

    fn execute(&mut self) -> Result<()> {
        #[cfg(feature = "ml")]
        {
            // Generate dummy predictions for postprocessing benchmark
            let num_classes = 1000usize;
            match self.task_type {
                MlTask::Classification => {
                    // Softmax + argmax over result_count independent predictions
                    for _ in 0..self.result_count {
                        let logits: Vec<f32> = (0..num_classes)
                            .map(|i| (i as f32 * 0.01_f32).sin())
                            .collect();
                        // Numerically stable softmax
                        let max_logit = logits.iter().copied().fold(f32::NEG_INFINITY, f32::max);
                        let exp_sum: f32 = logits.iter().map(|&x| (x - max_logit).exp()).sum();
                        let probs: Vec<f32> = logits
                            .iter()
                            .map(|&x| (x - max_logit).exp() / exp_sum)
                            .collect();
                        let _argmax = probs
                            .iter()
                            .enumerate()
                            .max_by(|(_, a), (_, b)| {
                                a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal)
                            })
                            .map(|(i, _)| i)
                            .unwrap_or(0);
                    }
                }
                MlTask::Detection => {
                    // Non-maximum suppression simulation
                    let boxes: Vec<(f32, f32, f32, f32)> = (0..self.result_count)
                        .map(|i| {
                            let x = (i % 10) as f32 * 100.0;
                            let y = (i / 10) as f32 * 100.0;
                            (x, y, x + 80.0, y + 80.0)
                        })
                        .collect();
                    let scores: Vec<f32> = (0..self.result_count)
                        .map(|i| i as f32 / self.result_count as f32)
                        .collect();
                    // Greedy NMS
                    let mut kept = vec![true; boxes.len()];
                    for i in 0..boxes.len() {
                        if !kept[i] {
                            continue;
                        }
                        for j in (i + 1)..boxes.len() {
                            if !kept[j] {
                                continue;
                            }
                            let iou = compute_iou(boxes[i], boxes[j]);
                            if iou > self.nms_threshold {
                                // Suppress lower-score box
                                if scores[i] >= scores[j] {
                                    kept[j] = false;
                                } else {
                                    kept[i] = false;
                                    break;
                                }
                            }
                        }
                    }
                    let _ = kept;
                }
                MlTask::Segmentation | MlTask::InstanceSegmentation => {
                    // Argmax per pixel for a segmentation map
                    let h = 224usize;
                    let w = 224usize;
                    let logit_map: Vec<f32> = (0..h * w * num_classes)
                        .map(|i| ((i % num_classes) as f32 * 0.001_f32).sin())
                        .collect();
                    let _mask: Vec<usize> = (0..h * w)
                        .map(|px| {
                            let base = px * num_classes;
                            logit_map[base..base + num_classes]
                                .iter()
                                .enumerate()
                                .max_by(|(_, a), (_, b)| {
                                    a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal)
                                })
                                .map(|(c, _)| c)
                                .unwrap_or(0)
                        })
                        .collect();
                }
            }
        }

        #[cfg(not(feature = "ml"))]
        {
            return Err(BenchError::missing_dependency("oxigdal-ml", "ml"));
        }

        Ok(())
    }

    fn teardown(&mut self) -> Result<()> {
        Ok(())
    }
}

/// End-to-end inference pipeline benchmark.
pub struct EndToEndPipelineScenario {
    model_path: PathBuf,
    input_dir: PathBuf,
    #[allow(dead_code)]
    task_type: MlTask,
    batch_size: usize,
    pipeline_count: usize,
}

impl EndToEndPipelineScenario {
    /// Creates a new end-to-end pipeline benchmark scenario.
    pub fn new<P1, P2>(model_path: P1, input_dir: P2, task_type: MlTask) -> Self
    where
        P1: Into<PathBuf>,
        P2: Into<PathBuf>,
    {
        Self {
            model_path: model_path.into(),
            input_dir: input_dir.into(),
            task_type,
            batch_size: 4,
            pipeline_count: 50,
        }
    }

    /// Sets the batch size.
    pub fn with_batch_size(mut self, batch_size: usize) -> Self {
        self.batch_size = batch_size;
        self
    }

    /// Sets the number of pipeline iterations.
    pub fn with_pipeline_count(mut self, count: usize) -> Self {
        self.pipeline_count = count;
        self
    }
}

impl BenchmarkScenario for EndToEndPipelineScenario {
    fn name(&self) -> &str {
        "end_to_end_pipeline"
    }

    fn description(&self) -> &str {
        "Benchmark end-to-end inference pipeline (preprocessing + inference + postprocessing)"
    }

    fn setup(&mut self) -> Result<()> {
        if !self.model_path.exists() {
            return Err(BenchError::scenario_failed(
                self.name(),
                format!("Model file does not exist: {}", self.model_path.display()),
            ));
        }

        if !self.input_dir.exists() {
            return Err(BenchError::scenario_failed(
                self.name(),
                format!(
                    "Input directory does not exist: {}",
                    self.input_dir.display()
                ),
            ));
        }

        Ok(())
    }

    fn execute(&mut self) -> Result<()> {
        #[cfg(feature = "ml")]
        {
            // Simulate end-to-end pipeline: preprocessing + inference + postprocessing
            let image_size = 3 * self.batch_size * (self.batch_size * 64) * (self.batch_size * 64);
            let raw_images: Vec<u8> = (0..image_size).map(|i| (i % 256) as u8).collect();
            for _pipeline_iter in 0..self.pipeline_count {
                // Step 1: Preprocessing — normalize to f32
                let preprocessed: Vec<f32> =
                    raw_images.iter().map(|&b| b as f32 / 255.0 - 0.5).collect();
                // Step 2: Inference — dot product "forward pass"
                let hidden_size = 128usize;
                let layer_out: Vec<f32> = (0..hidden_size)
                    .map(|j| {
                        preprocessed
                            .iter()
                            .enumerate()
                            .fold(0.0_f32, |acc, (i, &x)| {
                                acc + x * ((i + j) as f32 * 0.001_f32).cos()
                            })
                            / preprocessed.len() as f32
                    })
                    .collect();
                // Step 3: Postprocessing — softmax
                let max_val = layer_out.iter().copied().fold(f32::NEG_INFINITY, f32::max);
                let exp_sum: f32 = layer_out.iter().map(|&x| (x - max_val).exp()).sum();
                let _probs: Vec<f32> = layer_out
                    .iter()
                    .map(|&x| (x - max_val).exp() / exp_sum)
                    .collect();
            }
        }

        #[cfg(not(feature = "ml"))]
        {
            return Err(BenchError::missing_dependency("oxigdal-ml", "ml"));
        }

        Ok(())
    }

    fn teardown(&mut self) -> Result<()> {
        Ok(())
    }
}

/// Compute IoU (Intersection over Union) of two axis-aligned bounding boxes.
fn compute_iou(a: (f32, f32, f32, f32), b: (f32, f32, f32, f32)) -> f32 {
    let ix1 = a.0.max(b.0);
    let iy1 = a.1.max(b.1);
    let ix2 = a.2.min(b.2);
    let iy2 = a.3.min(b.3);
    let inter_w = (ix2 - ix1).max(0.0);
    let inter_h = (iy2 - iy1).max(0.0);
    let intersection = inter_w * inter_h;
    let area_a = (a.2 - a.0).max(0.0) * (a.3 - a.1).max(0.0);
    let area_b = (b.2 - b.0).max(0.0) * (b.3 - b.1).max(0.0);
    let union = area_a + area_b - intersection;
    if union <= 0.0 {
        0.0
    } else {
        intersection / union
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_onnx_inference_scenario_creation() {
        let scenario = OnnxInferenceScenario::new(
            std::env::temp_dir().join("model.onnx"),
            vec![1, 3, 224, 224],
        )
        .with_batch_size(8)
        .with_task_type(MlTask::Segmentation)
        .with_warmup_iterations(20);

        assert_eq!(scenario.name(), "onnx_inference");
        assert_eq!(scenario.batch_size, 8);
        assert_eq!(scenario.warmup_iterations, 20);
    }

    #[test]
    fn test_batch_processing_scenario_creation() {
        let scenario = BatchProcessingScenario::new(
            std::env::temp_dir().join("model.onnx"),
            std::env::temp_dir().join("images"),
        )
        .with_batch_sizes(vec![2, 4, 8])
        .with_task_type(MlTask::Detection);

        assert_eq!(scenario.name(), "batch_processing");
        assert_eq!(scenario.batch_sizes.len(), 3);
    }

    #[test]
    fn test_preprocessing_scenario_creation() {
        let scenario = PreprocessingScenario::new(std::env::temp_dir().join("images"))
            .with_steps(vec![
                PreprocessingStep::Resize,
                PreprocessingStep::Normalize,
                PreprocessingStep::ColorConversion,
            ])
            .with_image_count(50);

        assert_eq!(scenario.name(), "preprocessing");
        assert_eq!(scenario.preprocessing_steps.len(), 3);
        assert_eq!(scenario.image_count, 50);
    }

    #[test]
    fn test_postprocessing_scenario_creation() {
        let scenario = PostprocessingScenario::new(MlTask::Detection)
            .with_result_count(500)
            .with_nms_threshold(0.4);

        assert_eq!(scenario.name(), "postprocessing");
        assert_eq!(scenario.result_count, 500);
        assert_eq!(scenario.nms_threshold, 0.4);
    }

    #[test]
    fn test_end_to_end_pipeline_scenario_creation() {
        let scenario = EndToEndPipelineScenario::new(
            std::env::temp_dir().join("model.onnx"),
            std::env::temp_dir().join("images"),
            MlTask::Classification,
        )
        .with_batch_size(16)
        .with_pipeline_count(100);

        assert_eq!(scenario.name(), "end_to_end_pipeline");
        assert_eq!(scenario.batch_size, 16);
        assert_eq!(scenario.pipeline_count, 100);
    }
}