#[cfg(feature = "constellation")]
use constellation::*;
use std::{
env, path::PathBuf, time::{Duration, SystemTime}
};
use amadeus::prelude::*;
fn main() {
#[cfg(feature = "constellation")]
init(Resources::default());
let processes = env::args()
.nth(1)
.and_then(|arg| arg.parse::<usize>().ok())
.unwrap_or(10);
let local_pool_time = {
let local_pool = LocalPool::new();
run(&local_pool)
};
let thread_pool_time = {
let thread_pool = ThreadPool::new(processes).unwrap();
run(&thread_pool)
};
#[cfg(feature = "constellation")]
let process_pool_time = {
let process_pool = ProcessPool::new(processes, 1, Resources::default()).unwrap();
run(&process_pool)
};
#[cfg(not(feature = "constellation"))]
let process_pool_time = "-";
println!(
"in {:?} {:?} {:?}",
local_pool_time, thread_pool_time, process_pool_time
);
}
fn run<P: amadeus_core::pool::ProcessPool>(pool: &P) -> Duration {
let start = SystemTime::now();
#[derive(Data, Clone, PartialEq, PartialOrd, Debug)]
struct GameDerived {
a: String,
b: String,
c: String,
d: String,
e: u32,
f: String,
}
let rows =
Csv::<_, GameDerived>::new(vec![PathBuf::from("amadeus-testing/csv/game.csv")]).unwrap();
assert_eq!(
rows.dist_iter()
.map(FnMut!(|row: Result<_, _>| row.unwrap()))
.count(pool),
100_000
);
#[derive(Data, Clone, PartialEq, PartialOrd, Debug)]
struct GameDerived2 {
a: String,
b: String,
c: String,
d: String,
e: u64,
f: String,
}
let rows = Csv::<_, Value>::new(vec![PathBuf::from("amadeus-testing/csv/game.csv")]).unwrap();
assert_eq!(
rows.dist_iter()
.map(FnMut!(|row: Result<Value, _>| -> Value {
let value = row.unwrap();
let _: GameDerived2 = value.clone().downcast().unwrap();
value
}))
.count(pool),
100_000
);
start.elapsed().unwrap()
}