bench_to_json_dt/
bench_to_json_dt.rs1use std::collections::BTreeMap;
3
4use fp_columnar::Column;
5use fp_frame::DataFrame;
6use fp_index::Index;
7use fp_io::JsonOrient;
8
9fn main() {
10 let a: Vec<String> = std::env::args().collect();
11 let n: usize = a.get(1).and_then(|s| s.parse().ok()).unwrap_or(1_000_000);
12 let ints: Vec<i64> = (0..n as i64)
13 .map(|i| (i.wrapping_mul(2_654_435_761)) % 1_000_000)
14 .collect();
15 let base = 946_684_800_000_000_000i64;
16 let step = 37_000_000_000i64;
17 let dts: Vec<i64> = (0..n as i64).map(|i| base + i * step).collect();
18 let mut cols: BTreeMap<String, Column> = BTreeMap::new();
19 cols.insert("a".to_string(), Column::from_i64_values(ints));
20 cols.insert("t".to_string(), Column::from_datetime64_values(dts));
21 let frame = DataFrame::new(Index::new_known_unique_int64_unit_range(0, n), cols).unwrap();
22 let mut best = u128::MAX;
23 for _ in 0..6 {
24 let t = std::time::Instant::now();
25 let s = fp_io::write_json_string(&frame, JsonOrient::Records).unwrap();
26 std::hint::black_box(s.len());
27 let e = t.elapsed().as_nanos();
28 if e < best {
29 best = e;
30 }
31 }
32 println!(
33 "to_json(records) +dt n={n}: best={best}ns ({:.2}ms)",
34 best as f64 / 1e6
35 );
36}