Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ crate-type = ["cdylib", "rlib"]
name = "main"
harness = false

[[bench]]
name = "gen_trio_fixture"
harness = false

[workspace]
members = ["unit-gen"]

Expand All @@ -33,10 +37,12 @@ members = ["unit-gen"]
default = ["encoders", "filter", "timezone", "units", "c-api"]

# C API Features
c-api = ["c-api-filter", "c-api-json", "c-api-zinc"]
c-api = ["c-api-filter", "c-api-json", "c-api-zinc", "c-api-brio", "c-api-trio"]
c-api-filter = ["filter"]
c-api-zinc = ["zinc"]
c-api-json = ["json"]
c-api-brio = ["brio"]
c-api-trio = ["trio"]

# Lib features
value = ["units", "timezone", "encoders"]
Expand All @@ -46,7 +52,7 @@ units = ["units-db"]
units-db = []
timezone = ["timezone-db"]
timezone-db = []
encoders = ["value", "json", "zinc", "brio"]
encoders = ["value", "json", "zinc", "brio", "trio"]
json = ["json-encoding", "json-decoding"]
json-encoding = []
json-decoding = []
Expand All @@ -56,6 +62,9 @@ zinc-decoding = []
brio = ["brio-encoding", "brio-decoding"]
brio-encoding = []
brio-decoding = []
trio = ["trio-encoding", "trio-decoding"]
trio-encoding = ["zinc-encoding"]
trio-decoding = ["zinc-decoding"]

[dependencies]
serde = "1.0"
Expand Down
28 changes: 28 additions & 0 deletions benches/gen_trio_fixture.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (C) 2020 - 2024, J2 Innovations

//! Generates `benches/trio/points.trio` from `benches/json/points.json`.
//!
//! Run with:
//!
//! ```
//! cargo bench --bench gen_trio_fixture
//! ```

use libhaystack::encoding::trio::encode::TrioWriter;
use libhaystack::haystack::val::{Grid, Value};
use std::fs;

fn main() {
let json = fs::read_to_string("benches/json/points.json")
.expect("cannot read benches/json/points.json");

let value: Value = serde_json::from_str(&json).expect("JSON parse failed");
let grid = Grid::try_from(&value).expect("not a Grid");

let trio = TrioWriter::new().add_grid(&grid).to_trio_string();

fs::create_dir_all("benches/trio").expect("cannot create benches/trio");
fs::write("benches/trio/points.trio", &trio).expect("cannot write benches/trio/points.trio");

println!("Wrote {} bytes to benches/trio/points.trio", trio.len());
}
17 changes: 15 additions & 2 deletions benches/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use criterion::{criterion_group, criterion_main, Criterion};

use libhaystack::haystack::encoding::brio::decode::from_brio;
use libhaystack::haystack::encoding::trio::decode::TrioReader;
use libhaystack::haystack::encoding::zinc::decode::*;
use libhaystack::haystack::val::*;
use std::fs;
Expand Down Expand Up @@ -51,13 +52,25 @@ fn criterion_brio_parse(bench: &mut Criterion) {
});
}

fn criterion_trio_parse(bench: &mut Criterion) {
let string = fs::read_to_string("benches/trio/points.trio").expect("Invalid trio test file");
bench.bench_function("Trio parse points", |b| {
b.iter(|| {
let grid = TrioReader::grid_from_str(&string).expect("Grid");

assert!(!grid.is_empty());
});
});
}

criterion_group!(
benches,
criterion_zinc_parse,
criterion_json_parse,
criterion_brio_parse
criterion_brio_parse,
criterion_trio_parse
);
criterion_main!(benches);

#[cfg(never)]
#[cfg(any())]
fn main() {}
Loading
Loading