oxicode 0.2.2

A modern binary serialization library - successor to bincode
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
773
774
775
776
777
778
779
780
781
782
783
784
785
//! Comprehensive comparison benchmarks: oxicode vs bincode vs rkyv vs postcard vs borsh
//!
//! This benchmark compares oxicode against other popular binary serialization libraries:
//! - bincode: Binary encoding, similar design to oxicode
//! - rkyv: Zero-copy deserialization
//! - postcard: Embedded-friendly serialization
//! - borsh: Borsh binary serialization (used in Solana/NEAR)
//!
//! Run with: cargo bench --bench comparison_bench

use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use std::hint::black_box;

// Test data structures
#[derive(Clone)]
struct BenchmarkData {
    primitives: Vec<u64>,
    strings: Vec<String>,
    nested: Vec<NestedData>,
}

#[derive(Clone)]
struct NestedData {
    id: u64,
    name: String,
    values: Vec<f64>,
}

impl BenchmarkData {
    fn new(size: usize) -> Self {
        Self {
            primitives: (0..size as u64).collect(),
            strings: (0..size).map(|i| format!("String value {}", i)).collect(),
            nested: (0..size)
                .map(|i| NestedData {
                    id: i as u64,
                    name: format!("Nested {}", i),
                    values: vec![i as f64; 10],
                })
                .collect(),
        }
    }
}

// OxiCode types
mod oxicode_types {
    use oxicode::{Decode, Encode};

    #[derive(Clone, Encode, Decode)]
    pub struct BenchmarkData {
        pub primitives: Vec<u64>,
        pub strings: Vec<String>,
        pub nested: Vec<NestedData>,
    }

    #[derive(Clone, Encode, Decode)]
    pub struct NestedData {
        pub id: u64,
        pub name: String,
        pub values: Vec<f64>,
    }

    impl From<&super::BenchmarkData> for BenchmarkData {
        fn from(data: &super::BenchmarkData) -> Self {
            Self {
                primitives: data.primitives.clone(),
                strings: data.strings.clone(),
                nested: data
                    .nested
                    .iter()
                    .map(|n| NestedData {
                        id: n.id,
                        name: n.name.clone(),
                        values: n.values.clone(),
                    })
                    .collect(),
            }
        }
    }
}

// Bincode types
mod bincode_types {
    use bincode::{Decode, Encode};

    #[derive(Clone, Encode, Decode)]
    pub struct BenchmarkData {
        pub primitives: Vec<u64>,
        pub strings: Vec<String>,
        pub nested: Vec<NestedData>,
    }

    #[derive(Clone, Encode, Decode)]
    pub struct NestedData {
        pub id: u64,
        pub name: String,
        pub values: Vec<f64>,
    }

    impl From<&super::BenchmarkData> for BenchmarkData {
        fn from(data: &super::BenchmarkData) -> Self {
            Self {
                primitives: data.primitives.clone(),
                strings: data.strings.clone(),
                nested: data
                    .nested
                    .iter()
                    .map(|n| NestedData {
                        id: n.id,
                        name: n.name.clone(),
                        values: n.values.clone(),
                    })
                    .collect(),
            }
        }
    }
}

fn bench_encoding_comparison(c: &mut Criterion) {
    let mut group = c.benchmark_group("encoding_comparison");

    for size in [100, 1000, 10000] {
        let data = BenchmarkData::new(size);
        let oxi_data = oxicode_types::BenchmarkData::from(&data);
        let bin_data = bincode_types::BenchmarkData::from(&data);

        // Estimate throughput
        let estimated_bytes = size * (8 + 20 + 80); // rough estimate

        group.throughput(Throughput::Bytes(estimated_bytes as u64));

        // OxiCode
        group.bench_with_input(BenchmarkId::new("oxicode", size), &oxi_data, |b, data| {
            b.iter(|| {
                let bytes = oxicode::encode_to_vec(black_box(data)).unwrap();
                black_box(bytes);
            });
        });

        // Bincode
        group.bench_with_input(BenchmarkId::new("bincode", size), &bin_data, |b, data| {
            let config = bincode::config::standard();
            b.iter(|| {
                let bytes = bincode::encode_to_vec(black_box(data), black_box(config)).unwrap();
                black_box(bytes);
            });
        });
    }

    group.finish();
}

fn bench_decoding_comparison(c: &mut Criterion) {
    let mut group = c.benchmark_group("decoding_comparison");

    for size in [100, 1000, 10000] {
        let data = BenchmarkData::new(size);
        let oxi_data = oxicode_types::BenchmarkData::from(&data);
        let bin_data = bincode_types::BenchmarkData::from(&data);

        // Pre-encode data
        let oxi_bytes = oxicode::encode_to_vec(&oxi_data).unwrap();
        let bin_bytes = bincode::encode_to_vec(&bin_data, bincode::config::standard()).unwrap();

        let estimated_bytes = size * (8 + 20 + 80);
        group.throughput(Throughput::Bytes(estimated_bytes as u64));

        // OxiCode
        group.bench_with_input(BenchmarkId::new("oxicode", size), &oxi_bytes, |b, bytes| {
            b.iter(|| {
                let (decoded, _): (oxicode_types::BenchmarkData, _) =
                    oxicode::decode_from_slice(black_box(bytes)).unwrap();
                black_box(decoded);
            });
        });

        // Bincode
        group.bench_with_input(BenchmarkId::new("bincode", size), &bin_bytes, |b, bytes| {
            let config = bincode::config::standard();
            b.iter(|| {
                let (decoded, _): (bincode_types::BenchmarkData, _) =
                    bincode::decode_from_slice(black_box(bytes), black_box(config)).unwrap();
                black_box(decoded);
            });
        });
    }

    group.finish();
}

fn bench_size_comparison(c: &mut Criterion) {
    let group = c.benchmark_group("size_comparison");

    for size in [100, 1000, 10000] {
        let data = BenchmarkData::new(size);
        let oxi_data = oxicode_types::BenchmarkData::from(&data);
        let bin_data = bincode_types::BenchmarkData::from(&data);

        // Encode with each library
        let oxi_bytes = oxicode::encode_to_vec(&oxi_data).unwrap();
        let bin_bytes = bincode::encode_to_vec(&bin_data, bincode::config::standard()).unwrap();

        // Print size comparison (not a benchmark, just informative)
        println!("\nSize comparison for {} items:", size);
        println!("  OxiCode: {} bytes", oxi_bytes.len());
        println!("  Bincode: {} bytes", bin_bytes.len());
        println!(
            "  Ratio: {:.2}%",
            (oxi_bytes.len() as f64 / bin_bytes.len() as f64) * 100.0
        );
    }

    group.finish();
}

#[cfg(feature = "simd")]
fn bench_simd_arrays(c: &mut Criterion) {
    let mut group = c.benchmark_group("simd_arrays");

    for size in [100, 1000, 10000] {
        let data_i32: Vec<i32> = (0..size).collect();
        let data_u32: Vec<u32> = (0..size as u32).collect();
        let data_i64: Vec<i64> = (0..size as i64).collect();
        let data_u64: Vec<u64> = (0..size as u64).collect();
        let data_f32: Vec<f32> = (0..size).map(|i| i as f32).collect();
        let data_f64: Vec<f64> = (0..size).map(|i| i as f64).collect();

        group.throughput(Throughput::Bytes((size * 8) as u64));

        // i32 arrays
        group.bench_with_input(
            BenchmarkId::new("oxicode_i32_simd", size),
            &data_i32,
            |b, data| {
                b.iter(|| {
                    let bytes = oxicode::encode_to_vec(black_box(data)).unwrap();
                    black_box(bytes);
                });
            },
        );

        // u32 arrays
        group.bench_with_input(
            BenchmarkId::new("oxicode_u32_simd", size),
            &data_u32,
            |b, data| {
                b.iter(|| {
                    let bytes = oxicode::encode_to_vec(black_box(data)).unwrap();
                    black_box(bytes);
                });
            },
        );

        // i64 arrays
        group.bench_with_input(
            BenchmarkId::new("oxicode_i64_simd", size),
            &data_i64,
            |b, data| {
                b.iter(|| {
                    let bytes = oxicode::encode_to_vec(black_box(data)).unwrap();
                    black_box(bytes);
                });
            },
        );

        // u64 arrays
        group.bench_with_input(
            BenchmarkId::new("oxicode_u64_simd", size),
            &data_u64,
            |b, data| {
                b.iter(|| {
                    let bytes = oxicode::encode_to_vec(black_box(data)).unwrap();
                    black_box(bytes);
                });
            },
        );

        // f32 arrays
        group.bench_with_input(
            BenchmarkId::new("oxicode_f32_simd", size),
            &data_f32,
            |b, data| {
                b.iter(|| {
                    let bytes = oxicode::encode_to_vec(black_box(data)).unwrap();
                    black_box(bytes);
                });
            },
        );

        // f64 arrays
        group.bench_with_input(
            BenchmarkId::new("oxicode_f64_simd", size),
            &data_f64,
            |b, data| {
                b.iter(|| {
                    let bytes = oxicode::encode_to_vec(black_box(data)).unwrap();
                    black_box(bytes);
                });
            },
        );
    }

    group.finish();
}

#[cfg(any(feature = "compression-lz4", feature = "compression-zstd"))]
fn bench_compression_comparison(c: &mut Criterion) {
    use oxicode::compression::{compress, decompress, Compression};

    let mut group = c.benchmark_group("compression");

    // Three data profiles
    let highly_compressible: Vec<u8> = (0..10000).map(|i: usize| (i % 4) as u8).collect();
    let moderate: Vec<u8> = (0..10000).map(|i: usize| (i * 7 % 256) as u8).collect();
    let random_like: Vec<u8> = (0..10000)
        .map(|i: usize| (i.wrapping_mul(2654435761) % 256) as u8)
        .collect();

    let profiles = [
        ("highly_compressible", highly_compressible.as_slice()),
        ("moderate", moderate.as_slice()),
        ("random_like", random_like.as_slice()),
    ];

    for (profile_name, data) in &profiles {
        group.throughput(Throughput::Bytes(data.len() as u64));

        #[cfg(feature = "compression-lz4")]
        {
            group.bench_with_input(
                BenchmarkId::new(format!("lz4_compress/{}", profile_name), data.len()),
                data,
                |b, d| {
                    b.iter(|| {
                        let compressed = compress(black_box(d), Compression::Lz4).unwrap();
                        black_box(compressed);
                    });
                },
            );

            let lz4_compressed = compress(data, Compression::Lz4).unwrap();
            group.bench_with_input(
                BenchmarkId::new(format!("lz4_decompress/{}", profile_name), data.len()),
                lz4_compressed.as_slice(),
                |b, d| {
                    b.iter(|| {
                        let decompressed = decompress(black_box(d)).unwrap();
                        black_box(decompressed);
                    });
                },
            );
        }

        #[cfg(feature = "compression-zstd")]
        {
            group.bench_with_input(
                BenchmarkId::new(format!("zstd_compress/{}", profile_name), data.len()),
                data,
                |b, d| {
                    b.iter(|| {
                        let compressed = compress(black_box(d), Compression::Zstd).unwrap();
                        black_box(compressed);
                    });
                },
            );

            let zstd_compressed = compress(data, Compression::Zstd).unwrap();
            group.bench_with_input(
                BenchmarkId::new(format!("zstd_decompress/{}", profile_name), data.len()),
                zstd_compressed.as_slice(),
                |b, d| {
                    b.iter(|| {
                        let decompressed = decompress(black_box(d)).unwrap();
                        black_box(decompressed);
                    });
                },
            );
        }
    }

    group.finish();
}

fn bench_primitives_scaling(c: &mut Criterion) {
    let mut group = c.benchmark_group("primitives_scaling");

    // Encode Vec<f64> at various sizes to show throughput scaling
    for size in [64usize, 256, 1024, 4096, 16384] {
        let data: Vec<f64> = (0..size).map(|i| i as f64 * 0.1).collect();
        let oxi_encoded = oxicode::encode_to_vec(&data).unwrap();

        group.throughput(Throughput::Bytes((size * 8) as u64));

        group.bench_with_input(
            BenchmarkId::new("oxicode_encode_f64", size),
            &data,
            |b, d| {
                b.iter(|| {
                    let bytes = oxicode::encode_to_vec(black_box(d)).unwrap();
                    black_box(bytes);
                });
            },
        );

        group.bench_with_input(
            BenchmarkId::new("oxicode_decode_f64", size),
            oxi_encoded.as_slice(),
            |b, bytes| {
                b.iter(|| {
                    let (decoded, _): (Vec<f64>, _) =
                        oxicode::decode_from_slice(black_box(bytes)).unwrap();
                    black_box(decoded);
                });
            },
        );

        // Compare with bincode
        let bin_encoded = bincode::encode_to_vec(&data, bincode::config::standard()).unwrap();
        group.bench_with_input(
            BenchmarkId::new("bincode_encode_f64", size),
            &data,
            |b, d| {
                let config = bincode::config::standard();
                b.iter(|| {
                    let bytes = bincode::encode_to_vec(black_box(d), config).unwrap();
                    black_box(bytes);
                });
            },
        );

        group.bench_with_input(
            BenchmarkId::new("bincode_decode_f64", size),
            bin_encoded.as_slice(),
            |b, bytes| {
                let config = bincode::config::standard();
                b.iter(|| {
                    let (decoded, _): (Vec<f64>, _) =
                        bincode::decode_from_slice(black_box(bytes), config).unwrap();
                    black_box(decoded);
                });
            },
        );
    }

    group.finish();
}

fn bench_primitive_scaling(c: &mut Criterion) {
    let mut group = c.benchmark_group("primitive_scaling");

    for size in [100usize, 1_000, 10_000, 100_000] {
        let data: Vec<u64> = (0..size).map(|i| i as u64).collect();

        group.throughput(Throughput::Bytes((size * 8) as u64));

        group.bench_with_input(BenchmarkId::new("oxicode", size), &data, |b, data| {
            b.iter(|| {
                let bytes = oxicode::encode_to_vec(black_box(data)).unwrap();
                black_box(bytes);
            });
        });

        group.bench_with_input(BenchmarkId::new("bincode_v2", size), &data, |b, data| {
            let config = bincode::config::standard();
            b.iter(|| {
                let bytes = bincode::encode_to_vec(black_box(data), black_box(config)).unwrap();
                black_box(bytes);
            });
        });
    }

    group.finish();
}

mod complex_bench_oxi {
    use oxicode::{Decode, Encode};

    #[derive(Clone, Encode, Decode)]
    pub struct ComplexOxi {
        pub id: u64,
        pub label: String,
        pub values: Vec<f64>,
        pub count: u32,
        pub enabled: bool,
    }
}

mod complex_bench_bin {
    use bincode::{Decode, Encode};

    #[derive(Clone, Encode, Decode)]
    pub struct ComplexBin {
        pub id: u64,
        pub label: String,
        pub values: Vec<f64>,
        pub count: u32,
        pub enabled: bool,
    }
}

fn bench_complex_struct(c: &mut Criterion) {
    use complex_bench_bin::ComplexBin;
    use complex_bench_oxi::ComplexOxi;

    let mut group = c.benchmark_group("complex_struct");

    let oxi_val = ComplexOxi {
        id: 1001,
        label: "benchmark_complex_struct".to_string(),
        values: (0..50).map(|i| i as f64 * 0.1).collect(),
        count: 42,
        enabled: true,
    };
    let bin_val = ComplexBin {
        id: 1001,
        label: "benchmark_complex_struct".to_string(),
        values: (0..50).map(|i| i as f64 * 0.1).collect(),
        count: 42,
        enabled: true,
    };

    let estimated_bytes: u64 = 8 + 24 + 50 * 8 + 4 + 1; // rough size estimate
    group.throughput(Throughput::Bytes(estimated_bytes));

    group.bench_function("oxicode_complex_struct_encode", |b| {
        b.iter(|| {
            let bytes = oxicode::encode_to_vec(black_box(&oxi_val)).unwrap();
            black_box(bytes);
        });
    });

    group.bench_function("bincode_complex_struct_encode", |b| {
        let config = bincode::config::standard();
        b.iter(|| {
            let bytes = bincode::encode_to_vec(black_box(&bin_val), black_box(config)).unwrap();
            black_box(bytes);
        });
    });

    // Decode benchmarks
    let oxi_bytes = oxicode::encode_to_vec(&oxi_val).unwrap();
    let bin_bytes = bincode::encode_to_vec(&bin_val, bincode::config::standard()).unwrap();

    group.bench_function("oxicode_complex_struct_decode", |b| {
        b.iter(|| {
            let (decoded, _): (ComplexOxi, _) =
                oxicode::decode_from_slice(black_box(&oxi_bytes)).unwrap();
            black_box(decoded);
        });
    });

    group.bench_function("bincode_complex_struct_decode", |b| {
        let config = bincode::config::standard();
        b.iter(|| {
            let (decoded, _): (ComplexBin, _) =
                bincode::decode_from_slice(black_box(&bin_bytes), black_box(config)).unwrap();
            black_box(decoded);
        });
    });

    group.finish();
}

fn bench_option_encoding(c: &mut Criterion) {
    let mut group = c.benchmark_group("option_encoding");

    let some_val: Option<Vec<u8>> = Some((0..=255u8).collect());
    let none_val: Option<Vec<u8>> = None;

    let payload_bytes = some_val.as_ref().map(|v| v.len()).unwrap_or(0) as u64;
    group.throughput(Throughput::Bytes(payload_bytes));

    // Some variant
    group.bench_function("oxicode_option_some_encode", |b| {
        b.iter(|| {
            let bytes = oxicode::encode_to_vec(black_box(&some_val)).unwrap();
            black_box(bytes);
        });
    });

    group.bench_function("bincode_option_some_encode", |b| {
        let config = bincode::config::standard();
        b.iter(|| {
            let bytes = bincode::encode_to_vec(black_box(&some_val), black_box(config)).unwrap();
            black_box(bytes);
        });
    });

    // None variant
    group.bench_function("oxicode_option_none_encode", |b| {
        b.iter(|| {
            let bytes = oxicode::encode_to_vec(black_box(&none_val)).unwrap();
            black_box(bytes);
        });
    });

    group.bench_function("bincode_option_none_encode", |b| {
        let config = bincode::config::standard();
        b.iter(|| {
            let bytes = bincode::encode_to_vec(black_box(&none_val), black_box(config)).unwrap();
            black_box(bytes);
        });
    });

    // Decode Some
    let oxi_some_bytes = oxicode::encode_to_vec(&some_val).unwrap();
    let bin_some_bytes = bincode::encode_to_vec(&some_val, bincode::config::standard()).unwrap();

    group.bench_function("oxicode_option_some_decode", |b| {
        b.iter(|| {
            let (decoded, _): (Option<Vec<u8>>, _) =
                oxicode::decode_from_slice(black_box(&oxi_some_bytes)).unwrap();
            black_box(decoded);
        });
    });

    group.bench_function("bincode_option_some_decode", |b| {
        let config = bincode::config::standard();
        b.iter(|| {
            let (decoded, _): (Option<Vec<u8>>, _) =
                bincode::decode_from_slice(black_box(&bin_some_bytes), black_box(config)).unwrap();
            black_box(decoded);
        });
    });

    group.finish();
}

fn bench_string_encoding(c: &mut Criterion) {
    let mut group = c.benchmark_group("string_encoding");

    let strings: Vec<String> = (0..1000).map(|i| format!("key_{}", i)).collect();

    // Estimate throughput as sum of string bytes
    let total_bytes: usize = strings.iter().map(|s| s.len()).sum();
    group.throughput(Throughput::Bytes(total_bytes as u64));

    group.bench_function("oxicode_vec_string", |b| {
        b.iter(|| {
            let bytes = oxicode::encode_to_vec(black_box(&strings)).unwrap();
            black_box(bytes);
        });
    });

    group.bench_function("bincode_v2_vec_string", |b| {
        let config = bincode::config::standard();
        b.iter(|| {
            let bytes = bincode::encode_to_vec(black_box(&strings), black_box(config)).unwrap();
            black_box(bytes);
        });
    });

    // Also benchmark decoding to round out the comparison
    let oxi_bytes = oxicode::encode_to_vec(&strings).unwrap();
    let bin_bytes = bincode::encode_to_vec(&strings, bincode::config::standard()).unwrap();

    group.bench_function("oxicode_vec_string_decode", |b| {
        b.iter(|| {
            let (decoded, _): (Vec<String>, _) =
                oxicode::decode_from_slice(black_box(&oxi_bytes)).unwrap();
            black_box(decoded);
        });
    });

    group.bench_function("bincode_v2_vec_string_decode", |b| {
        let config = bincode::config::standard();
        b.iter(|| {
            let (decoded, _): (Vec<String>, _) =
                bincode::decode_from_slice(black_box(&bin_bytes), black_box(config)).unwrap();
            black_box(decoded);
        });
    });

    group.finish();
}

fn bench_roundtrip(c: &mut Criterion) {
    let mut group = c.benchmark_group("roundtrip");

    for size in [100, 1000, 10000] {
        let data = BenchmarkData::new(size);
        let oxi_data = oxicode_types::BenchmarkData::from(&data);
        let bin_data = bincode_types::BenchmarkData::from(&data);

        let estimated_bytes = size * (8 + 20 + 80);
        group.throughput(Throughput::Bytes(estimated_bytes as u64));

        // OxiCode roundtrip
        group.bench_with_input(BenchmarkId::new("oxicode", size), &oxi_data, |b, data| {
            b.iter(|| {
                let bytes = oxicode::encode_to_vec(black_box(data)).unwrap();
                let (decoded, _): (oxicode_types::BenchmarkData, _) =
                    oxicode::decode_from_slice(&bytes).unwrap();
                black_box(decoded);
            });
        });

        // Bincode roundtrip
        group.bench_with_input(BenchmarkId::new("bincode", size), &bin_data, |b, data| {
            let config = bincode::config::standard();
            b.iter(|| {
                let bytes = bincode::encode_to_vec(black_box(data), config).unwrap();
                let (decoded, _): (bincode_types::BenchmarkData, _) =
                    bincode::decode_from_slice(&bytes, config).unwrap();
                black_box(decoded);
            });
        });
    }

    group.finish();
}

#[cfg(all(
    feature = "simd",
    any(feature = "compression-lz4", feature = "compression-zstd")
))]
criterion_group!(
    benches,
    bench_encoding_comparison,
    bench_decoding_comparison,
    bench_size_comparison,
    bench_simd_arrays,
    bench_roundtrip,
    bench_compression_comparison,
    bench_primitives_scaling,
    bench_primitive_scaling,
    bench_string_encoding,
    bench_complex_struct,
    bench_option_encoding
);

#[cfg(all(
    feature = "simd",
    not(any(feature = "compression-lz4", feature = "compression-zstd"))
))]
criterion_group!(
    benches,
    bench_encoding_comparison,
    bench_decoding_comparison,
    bench_size_comparison,
    bench_simd_arrays,
    bench_roundtrip,
    bench_primitives_scaling,
    bench_primitive_scaling,
    bench_string_encoding,
    bench_complex_struct,
    bench_option_encoding
);

#[cfg(all(
    not(feature = "simd"),
    any(feature = "compression-lz4", feature = "compression-zstd")
))]
criterion_group!(
    benches,
    bench_encoding_comparison,
    bench_decoding_comparison,
    bench_size_comparison,
    bench_roundtrip,
    bench_compression_comparison,
    bench_primitives_scaling,
    bench_primitive_scaling,
    bench_string_encoding,
    bench_complex_struct,
    bench_option_encoding
);

#[cfg(all(
    not(feature = "simd"),
    not(any(feature = "compression-lz4", feature = "compression-zstd"))
))]
criterion_group!(
    benches,
    bench_encoding_comparison,
    bench_decoding_comparison,
    bench_size_comparison,
    bench_roundtrip,
    bench_primitives_scaling,
    bench_primitive_scaling,
    bench_string_encoding,
    bench_complex_struct,
    bench_option_encoding
);

criterion_main!(benches);