feat(components): add ThermoState generators and Eurovent backend demo
This commit is contained in:
54
crates/fluids/benches/cache_10k.rs
Normal file
54
crates/fluids/benches/cache_10k.rs
Normal file
@@ -0,0 +1,54 @@
|
||||
//! Benchmark: 10k repeated (P,T) queries — cached vs uncached (Story 2.4 AC#4).
|
||||
//!
|
||||
//! Compares throughput of CachedBackend vs raw backend for repeated same-state queries.
|
||||
//! Cached path should show significant speedup when the backend is expensive (e.g. CoolProp).
|
||||
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
use entropyk_fluids::{
|
||||
CachedBackend, FluidBackend, FluidId, Property, ThermoState, TestBackend,
|
||||
};
|
||||
use entropyk_core::{Pressure, Temperature};
|
||||
|
||||
const N_QUERIES: u32 = 10_000;
|
||||
|
||||
fn bench_uncached_10k(c: &mut Criterion) {
|
||||
let backend = TestBackend::new();
|
||||
let state = ThermoState::from_pt(
|
||||
Pressure::from_bar(1.0),
|
||||
Temperature::from_celsius(25.0),
|
||||
);
|
||||
let fluid = FluidId::new("R134a");
|
||||
|
||||
c.bench_function("uncached_10k_same_state", |b| {
|
||||
b.iter(|| {
|
||||
for _ in 0..N_QUERIES {
|
||||
black_box(
|
||||
backend.property(fluid.clone(), Property::Density, state.clone()).unwrap(),
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn bench_cached_10k(c: &mut Criterion) {
|
||||
let inner = TestBackend::new();
|
||||
let cached = CachedBackend::new(inner);
|
||||
let state = ThermoState::from_pt(
|
||||
Pressure::from_bar(1.0),
|
||||
Temperature::from_celsius(25.0),
|
||||
);
|
||||
let fluid = FluidId::new("R134a");
|
||||
|
||||
c.bench_function("cached_10k_same_state", |b| {
|
||||
b.iter(|| {
|
||||
for _ in 0..N_QUERIES {
|
||||
black_box(
|
||||
cached.property(fluid.clone(), Property::Density, state.clone()).unwrap(),
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(benches, bench_uncached_10k, bench_cached_10k);
|
||||
criterion_main!(benches);
|
||||
Reference in New Issue
Block a user