summaryrefslogtreecommitdiff
path: root/benches/jpeg_parsing.rs
diff options
context:
space:
mode:
Diffstat (limited to 'benches/jpeg_parsing.rs')
-rw-r--r--benches/jpeg_parsing.rs57
1 files changed, 57 insertions, 0 deletions
diff --git a/benches/jpeg_parsing.rs b/benches/jpeg_parsing.rs
new file mode 100644
index 0000000..6d3e4fc
--- /dev/null
+++ b/benches/jpeg_parsing.rs
@@ -0,0 +1,57 @@
+//! Benchmark for JPEG parsing performance
+
+use criterion::{black_box, criterion_group, criterion_main, Criterion};
+use geek_szitman_supercamera::protocol::jpeg::JpegParser;
+
+// Sample JPEG data for benchmarking
+const SAMPLE_JPEG: &[u8] = &[
+ 0xFF, 0xD8, // SOI
+ 0xFF, 0xE0, // APP0
+ 0x00, 0x10, // Length
+ 0x4A, 0x46, 0x49, 0x46, 0x00, // "JFIF\0"
+ 0x01, 0x01, // Version
+ 0x00, // Units
+ 0x00, 0x01, // Density
+ 0x00, 0x01, 0x00, 0x00, // No thumbnail
+ 0xFF, 0xC0, // SOF0
+ 0x00, 0x0B, // Length
+ 0x08, // Precision
+ 0x00, 0x40, // Height (64)
+ 0x00, 0x40, // Width (64)
+ 0x03, // Components
+ 0x01, 0x11, 0x00, // Y component
+ 0x02, 0x11, 0x01, // U component
+ 0x03, 0x11, 0x01, // V component
+ 0xFF, 0xD9, // EOI
+];
+
+fn benchmark_jpeg_parsing(c: &mut Criterion) {
+ let parser = JpegParser::new();
+
+ c.bench_function("parse_jpeg_dimensions", |b| {
+ b.iter(|| parser.parse_dimensions(black_box(SAMPLE_JPEG)))
+ });
+
+ c.bench_function("parse_jpeg_metadata", |b| {
+ b.iter(|| parser.parse_metadata(black_box(SAMPLE_JPEG)))
+ });
+
+ c.bench_function("validate_jpeg", |b| {
+ b.iter(|| parser.validate_jpeg(black_box(SAMPLE_JPEG)))
+ });
+}
+
+fn benchmark_jpeg_parser_creation(c: &mut Criterion) {
+ c.bench_function("create_jpeg_parser", |b| b.iter(|| JpegParser::new()));
+
+ c.bench_function("create_jpeg_parser_with_debug", |b| {
+ b.iter(|| JpegParser::new_with_debug(true))
+ });
+}
+
+criterion_group!(
+ benches,
+ benchmark_jpeg_parsing,
+ benchmark_jpeg_parser_creation
+);
+criterion_main!(benches);