Skip to main content

facet_json_classics/
lib.rs

1//! Classic JSON benchmark fixtures from nativejson-benchmark.
2//!
3//! Provides compressed fixtures and helper functions for benchmarking JSON parsers.
4//! Files are stored as brotli-compressed data and decompressed on demand.
5
6use std::sync::LazyLock;
7
8/// Decompress a brotli-compressed fixture
9fn decompress(compressed: &[u8]) -> Vec<u8> {
10    let mut decompressed = Vec::new();
11    brotli::BrotliDecompress(&mut std::io::Cursor::new(compressed), &mut decompressed)
12        .expect("Failed to decompress fixture");
13    decompressed
14}
15
16/// citm_catalog.json - Event catalog data (~1.7MB uncompressed)
17///
18/// Contains event/performance data with many nested structs, hashmaps, and arrays.
19pub static CITM_CATALOG: LazyLock<String> = LazyLock::new(|| {
20    let compressed = include_bytes!(concat!(
21        env!("CARGO_MANIFEST_DIR"),
22        "/fixtures/citm_catalog.json.br"
23    ));
24    String::from_utf8(decompress(compressed)).expect("citm_catalog.json should be valid UTF-8")
25});
26
27/// twitter.json - Social media API response (~632KB uncompressed)
28///
29/// Contains tweet data with nested user objects, entities, and optional fields.
30pub static TWITTER: LazyLock<String> = LazyLock::new(|| {
31    let compressed = include_bytes!(concat!(
32        env!("CARGO_MANIFEST_DIR"),
33        "/fixtures/twitter.json.br"
34    ));
35    String::from_utf8(decompress(compressed)).expect("twitter.json should be valid UTF-8")
36});
37
38/// canada.json - GeoJSON polygon coordinates (~2.3MB uncompressed)
39///
40/// Contains deeply nested arrays of floating-point coordinates.
41pub static CANADA: LazyLock<String> = LazyLock::new(|| {
42    let compressed = include_bytes!(concat!(
43        env!("CARGO_MANIFEST_DIR"),
44        "/fixtures/canada.json.br"
45    ));
46    String::from_utf8(decompress(compressed)).expect("canada.json should be valid UTF-8")
47});