use std::{collections::BTreeMap, time::Instant};
use fp_columnar::Column;
use fp_frame::DataFrame;
use fp_index::{Index, IndexLabel};
use fp_types::Scalar;
fn main() {
let args: Vec<String> = std::env::args().collect();
let n: usize = args.get(1).and_then(|s| s.parse().ok()).unwrap_or(500_000);
let k: usize = args.get(2).and_then(|s| s.parse().ok()).unwrap_or(5);
let iters: usize = args.get(3).and_then(|s| s.parse().ok()).unwrap_or(20);
let index = Index::new((0..n as i64).map(IndexLabel::Int64).collect());
let mut cols = BTreeMap::new();
let mut order = Vec::new();
let mut st: u64 = 0x51ed_2701_aa17_3c9f;
for c in 0..k {
let name = format!("c{c}");
let vals: Vec<Scalar> = (0..n)
.map(|i| {
if c == 0 {
st = st.wrapping_mul(6_364_136_223_846_793_005).wrapping_add(1);
Scalar::Float64(((st >> 11) as f64) / (1u64 << 53) as f64 * 1e6)
} else {
Scalar::Float64((i + c) as f64 * 1.5)
}
})
.collect();
cols.insert(name.clone(), Column::from_values(vals).unwrap());
order.push(name);
}
let df = DataFrame::new_with_column_order(index, cols, order).unwrap();
let mut best = u128::MAX;
for _ in 0..iters {
let t = Instant::now();
let out = df.sort_values("c0", true).expect("sort_values");
let e = t.elapsed().as_nanos();
std::hint::black_box(&out);
if e < best {
best = e;
}
}
println!("sort_values_df n={n} k={k}: best={best}ns");
}