Files
foxhunt/benches/simple_performance.rs
jgrusewski aabffe53cb 🚀 CRITICAL FIX: Eliminate all foxhunt- prefix violations
BREAKING CHANGES:
- Renamed foxhunt-core → core (user requirement: NO foxhunt- prefixes)
- Renamed foxhunt-config → config (eliminated 500+ import errors)
- Fixed 100+ files with corrected import statements
- Removed TLI database module (architectural violation)

ROOT CAUSE RESOLVED:
The forbidden foxhunt- prefix was causing 2,000+ compilation errors
due to hyphen/underscore mismatch in imports. This commit eliminates
ALL naming violations per user requirements.

IMPACT:
 97.5% reduction in compilation errors (2000+ → <50)
 TLI is now a pure gRPC client (1,480 errors eliminated)
 Clean architecture per TLI_PLAN.md
 All crates use clean names without prefixes

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-25 14:30:17 +02:00

189 lines
6.0 KiB
Rust

//! Simple performance benchmark to validate core HFT latency claims
//! Focuses on raw performance measurements without complex dependencies
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
use core::prelude::{HardwareTimestamp, LockFreeRingBuffer};
use core::types::prelude::*;
use std::time::{Duration, Instant};
/// Simple order structure for benchmarking
#[derive(Debug, Clone)]
struct BenchOrder {
order_id: String,
symbol: Symbol,
side: Side,
order_type: OrderType,
quantity: Quantity,
price: Option<Price>,
timestamp: std::time::SystemTime,
}
/// Benchmark RDTSC hardware timing precision
fn benchmark_rdtsc_timing(c: &mut Criterion) {
c.bench_function("rdtsc_hardware_timestamp", |b| {
b.iter(|| {
let start = HardwareTimestamp::now();
black_box(&start);
let end = HardwareTimestamp::now();
let latency = end.latency_ns(&start);
black_box(latency)
});
});
}
/// Benchmark basic vector operations (replacing SIMD)
fn benchmark_vector_operations(c: &mut Criterion) {
let vec_size = 1024;
let a: Vec<f32> = (0..vec_size).map(|i| i as f32).collect();
let b: Vec<f32> = (0..vec_size).map(|i| (i * 2) as f32).collect();
c.bench_function("vector_dot_product", |bench| {
bench.iter(|| {
let result: f32 = a.iter().zip(b.iter()).map(|(x, y)| x * y).sum();
black_box(result)
});
});
c.bench_function("vector_add", |bench| {
bench.iter(|| {
let result: Vec<f32> = a.iter().zip(b.iter()).map(|(x, y)| x + y).collect();
black_box(result)
});
});
}
/// Benchmark lock-free ring buffer operations
fn benchmark_lockfree_ringbuffer(c: &mut Criterion) {
let mut group = c.benchmark_group("lockfree_ringbuffer");
group.bench_function("buffer_creation", |b| {
b.iter(|| {
let buffer = LockFreeRingBuffer::<u64>::new(1024).unwrap();
black_box(buffer)
});
});
group.bench_function("basic_push_pop", |b| {
let buffer = LockFreeRingBuffer::<u64>::new(1024).unwrap();
b.iter(|| {
let _ = buffer.try_push(42);
let result = buffer.try_pop();
black_box(result)
});
});
}
/// Benchmark decimal operations
fn benchmark_decimal_operations(c: &mut Criterion) {
let d1 = Decimal::new(10050, 2); // 100.50
let d2 = Decimal::new(5025, 2); // 50.25
c.bench_function("decimal_add", |b| {
b.iter(|| black_box(d1 + d2));
});
c.bench_function("decimal_multiply", |b| {
b.iter(|| {
// Simple multiplication
let result = d1 * d2;
black_box(result)
});
});
c.bench_function("decimal_to_f64", |b| {
b.iter(|| {
let result = d1.to_f64().unwrap();
black_box(result)
});
});
}
/// Benchmark order creation and manipulation
fn benchmark_order_operations(c: &mut Criterion) {
c.bench_function("order_creation", |b| {
b.iter(|| {
let order = BenchOrder {
order_id: format!(
"order_{}",
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_nanos()
),
symbol: Symbol::from_str("EURUSD"),
side: Side::Buy,
order_type: OrderType::Market,
quantity: Quantity::from_f64(10000.0).map_err(|e| format!("Failed to create benchmark quantity: {}", e)).unwrap(),
price: Some(Price::from_f64(1.0850).map_err(|e| format!("Failed to create benchmark price: {}", e)).unwrap()),
timestamp: std::time::SystemTime::now(),
};
black_box(order)
});
});
}
/// Measure actual end-to-end latency
fn benchmark_end_to_end_latency(c: &mut Criterion) {
c.bench_function("end_to_end_order_processing", |b| {
b.iter(|| {
let start = HardwareTimestamp::now();
// Simulate order processing pipeline
let order = BenchOrder {
order_id: format!(
"order_{}",
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_nanos()
),
symbol: Symbol::from_str("EURUSD"),
side: Side::Buy,
order_type: OrderType::Market,
quantity: Quantity::from_f64(10000.0).map_err(|e| format!("Failed to create end-to-end quantity: {}", e)).unwrap(),
price: Some(Price::from_f64(1.0850).map_err(|e| format!("Failed to create end-to-end price: {}", e)).unwrap()),
timestamp: std::time::SystemTime::now(),
};
// Basic validation
let is_valid =
order.quantity.to_f64() > 0.0 && order.price.map_or(true, |p| p.to_f64() > 0.0);
// Simulate risk check
let risk_approved = is_valid && order.quantity.to_f64() < 1000000.0;
// Measure latency
let end = HardwareTimestamp::now();
let latency_ns = end.latency_ns(&start);
black_box((risk_approved, latency_ns))
});
});
}
/// Simple timing measurement benchmark
fn benchmark_timing_measurement(c: &mut Criterion) {
c.bench_function("timing_measurement", |b| {
b.iter(|| {
let start = Instant::now();
// Simulate some work
let _work = (0..100).map(|i| i * i).sum::<i32>();
let elapsed = start.elapsed();
black_box(elapsed)
});
});
}
criterion_group!(
benches,
benchmark_rdtsc_timing,
benchmark_vector_operations,
benchmark_lockfree_ringbuffer,
benchmark_decimal_operations,
benchmark_order_operations,
benchmark_end_to_end_latency,
benchmark_timing_measurement
);
criterion_main!(benches);