471 lines
14 KiB
Rust
471 lines
14 KiB
Rust
//! Configuration management performance benchmarks
|
|
//!
|
|
//! This benchmark suite measures the performance of FXT configuration
|
|
//! operations including validation, serialization, and database operations.
|
|
//!
|
|
//! ============================================================================
|
|
//! TEMPORARILY DISABLED - Missing dependencies
|
|
//! ============================================================================
|
|
//!
|
|
//! This benchmark file uses the `futures` crate which is not a dependency.
|
|
//!
|
|
//! TODO: Fix by either:
|
|
//! 1. Adding `futures` to tli/Cargo.toml [dev-dependencies]
|
|
//! 2. Rewriting benchmarks to avoid futures usage
|
|
//!
|
|
//! See Wave 36 - Agent 10 for context
|
|
//! ============================================================================
|
|
#![allow(unused_crate_dependencies)]
|
|
|
|
// DISABLED: use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
|
|
// DISABLED: use std::collections::HashMap;
|
|
// DISABLED: use std::time::Duration;
|
|
// DISABLED: use fxt::prelude::*;
|
|
// DISABLED: use fxt::types::*;
|
|
// DISABLED: use tokio::runtime::Runtime;
|
|
|
|
/*
|
|
|
|
/// Benchmark timestamp conversion operations
|
|
fn bench_timestamp_conversions(c: &mut Criterion) {
|
|
let mut group = c.benchmark_group("timestamp_conversions");
|
|
|
|
// Test different timestamp ranges
|
|
let timestamps = vec![
|
|
0i64,
|
|
1_000_000_000, // 1 second
|
|
1_000_000_000_000, // 1000 seconds
|
|
1_640_995_200_000_000_000, // 2022-01-01 in nanoseconds
|
|
];
|
|
|
|
for timestamp in timestamps {
|
|
group.bench_with_input(
|
|
BenchmarkId::new("unix_nanos_to_system_time", timestamp),
|
|
×tamp,
|
|
|b, &ts| {
|
|
b.iter(|| {
|
|
let system_time = unix_nanos_to_system_time(black_box(ts));
|
|
black_box(system_time)
|
|
})
|
|
},
|
|
);
|
|
|
|
group.bench_with_input(
|
|
BenchmarkId::new("system_time_to_unix_nanos", timestamp),
|
|
×tamp,
|
|
|b, &ts| {
|
|
let system_time = unix_nanos_to_system_time(ts);
|
|
b.iter(|| {
|
|
let nanos = system_time_to_unix_nanos(black_box(system_time));
|
|
black_box(nanos)
|
|
})
|
|
},
|
|
);
|
|
}
|
|
|
|
// Benchmark current timestamp generation
|
|
group.bench_function("current_unix_nanos", |b| {
|
|
b.iter(|| {
|
|
let timestamp = current_unix_nanos();
|
|
black_box(timestamp)
|
|
})
|
|
});
|
|
|
|
group.finish();
|
|
}
|
|
|
|
/// Benchmark validation functions
|
|
fn bench_validation_operations(c: &mut Criterion) {
|
|
let mut group = c.benchmark_group("validation_operations");
|
|
|
|
// Symbol validation
|
|
let symbols = vec![
|
|
"AAPL",
|
|
"BTC.USD",
|
|
"EUR-USD",
|
|
"SPX_500",
|
|
"VERY_LONG_SYMBOL_NAME",
|
|
];
|
|
|
|
for symbol in symbols {
|
|
group.bench_with_input(
|
|
BenchmarkId::new("validate_symbol", symbol),
|
|
&symbol,
|
|
|b, &s| {
|
|
b.iter(|| {
|
|
let result = validate_symbol(black_box(s));
|
|
black_box(result)
|
|
})
|
|
},
|
|
);
|
|
}
|
|
|
|
// Quantity validation
|
|
let quantities = vec![0.001, 1.0, 100.0, 10000.0, 1_000_000.0];
|
|
|
|
for quantity in quantities {
|
|
group.bench_with_input(
|
|
BenchmarkId::new("validate_quantity", quantity),
|
|
&quantity,
|
|
|b, &q| {
|
|
b.iter(|| {
|
|
let result = validate_quantity(black_box(q));
|
|
black_box(result)
|
|
})
|
|
},
|
|
);
|
|
}
|
|
|
|
// Price validation
|
|
let prices = vec![0.01, 1.0, 100.0, 1000.0, 50000.0];
|
|
|
|
for price in prices {
|
|
group.bench_with_input(
|
|
BenchmarkId::new("validate_price", price),
|
|
&price,
|
|
|b, &p| {
|
|
b.iter(|| {
|
|
let result = validate_price(black_box(p));
|
|
black_box(result)
|
|
})
|
|
},
|
|
);
|
|
}
|
|
|
|
group.finish();
|
|
}
|
|
|
|
/// Benchmark type conversions
|
|
fn bench_type_conversions(c: &mut Criterion) {
|
|
let mut group = c.benchmark_group("type_conversions");
|
|
|
|
use common::OrderSide;
|
|
use fxt::proto::trading::{OrderStatus, OrderType};
|
|
|
|
// Order side conversions
|
|
let sides = vec![OrderSide::Buy, OrderSide::Sell];
|
|
|
|
for side in sides {
|
|
group.bench_with_input(
|
|
BenchmarkId::new("order_side_to_string", format!("{:?}", side)),
|
|
&side,
|
|
|b, &s| {
|
|
b.iter(|| {
|
|
let result = order_side_to_string(black_box(s));
|
|
black_box(result)
|
|
})
|
|
},
|
|
);
|
|
}
|
|
|
|
let side_strings = vec!["BUY", "SELL", "buy", "sell"];
|
|
|
|
for side_str in side_strings {
|
|
group.bench_with_input(
|
|
BenchmarkId::new("string_to_order_side", side_str),
|
|
&side_str,
|
|
|b, &s| {
|
|
b.iter(|| {
|
|
let result = string_to_order_side(black_box(s));
|
|
black_box(result)
|
|
})
|
|
},
|
|
);
|
|
}
|
|
|
|
// Order type conversions
|
|
let types = vec![
|
|
OrderType::Market,
|
|
OrderType::Limit,
|
|
OrderType::Stop,
|
|
OrderType::StopLimit,
|
|
];
|
|
|
|
for order_type in types {
|
|
group.bench_with_input(
|
|
BenchmarkId::new("order_type_to_string", format!("{:?}", order_type)),
|
|
&order_type,
|
|
|b, &ot| {
|
|
b.iter(|| {
|
|
let result = order_type_to_string(black_box(ot));
|
|
black_box(result)
|
|
})
|
|
},
|
|
);
|
|
}
|
|
|
|
// System status conversions
|
|
let statuses = vec![
|
|
TliSystemStatus::Healthy,
|
|
TliSystemStatus::Warning,
|
|
TliSystemStatus::Degraded,
|
|
TliSystemStatus::Critical,
|
|
];
|
|
|
|
for status in statuses {
|
|
group.bench_with_input(
|
|
BenchmarkId::new("system_status_to_string", format!("{:?}", status)),
|
|
&status,
|
|
|b, &st| {
|
|
b.iter(|| {
|
|
let result = system_status_to_string(black_box(st));
|
|
black_box(result)
|
|
})
|
|
},
|
|
);
|
|
}
|
|
|
|
group.finish();
|
|
}
|
|
|
|
/// Benchmark metric creation
|
|
fn bench_metric_creation(c: &mut Criterion) {
|
|
let mut group = c.benchmark_group("metric_creation");
|
|
|
|
// Different label sizes
|
|
let label_counts = vec![0, 1, 5, 10, 20];
|
|
|
|
for label_count in label_counts {
|
|
let mut labels = HashMap::new();
|
|
for i in 0..label_count {
|
|
labels.insert(format!("label_{}", i), format!("value_{}", i));
|
|
}
|
|
|
|
group.bench_with_input(
|
|
BenchmarkId::new("create_metric", label_count),
|
|
&labels,
|
|
|b, labels| {
|
|
b.iter(|| {
|
|
let metric = create_metric(
|
|
"test_metric".to_string(),
|
|
black_box(42.5),
|
|
"count".to_string(),
|
|
black_box(labels.clone()),
|
|
);
|
|
black_box(metric)
|
|
})
|
|
},
|
|
);
|
|
}
|
|
|
|
group.finish();
|
|
}
|
|
|
|
/// Benchmark position calculations
|
|
fn bench_position_calculations(c: &mut Criterion) {
|
|
let mut group = c.benchmark_group("position_calculations");
|
|
|
|
// Different position sizes
|
|
let positions = vec![
|
|
(100.0, 150.0, 140.0), // Small position
|
|
(1000.0, 50.0, 45.0), // Medium position
|
|
(10000.0, 25.50, 26.75), // Large position
|
|
(-500.0, 100.0, 105.0), // Short position
|
|
];
|
|
|
|
for (i, (quantity, market_price, average_cost)) in positions.into_iter().enumerate() {
|
|
group.bench_with_input(
|
|
BenchmarkId::new("create_proto_position", i),
|
|
&(*quantity, *market_price, *average_cost),
|
|
|b, &(q, mp, ac)| {
|
|
b.iter(|| {
|
|
let position = create_proto_position(
|
|
"TEST".to_string(),
|
|
black_box(q),
|
|
black_box(mp),
|
|
black_box(ac),
|
|
);
|
|
black_box(position)
|
|
})
|
|
},
|
|
);
|
|
}
|
|
|
|
group.finish();
|
|
}
|
|
|
|
/// Benchmark concurrent validation operations
|
|
fn bench_concurrent_validation(c: &mut Criterion) {
|
|
let rt = Runtime::new().unwrap();
|
|
|
|
let mut group = c.benchmark_group("concurrent_validation");
|
|
group.measurement_time(Duration::from_secs(10));
|
|
|
|
let thread_counts = vec![1, 2, 4, 8, 16];
|
|
|
|
for thread_count in thread_counts {
|
|
group.bench_with_input(
|
|
BenchmarkId::new("parallel_symbol_validation", thread_count),
|
|
&thread_count,
|
|
|b, &tc| {
|
|
b.to_async(&rt).iter(|| async move {
|
|
let symbols = vec!["AAPL", "MSFT", "GOOGL", "AMZN", "TSLA"];
|
|
|
|
let tasks = (0..tc).map(|_| {
|
|
let symbols = symbols.clone();
|
|
tokio::spawn(async move {
|
|
for symbol in symbols {
|
|
let _ = validate_symbol(symbol);
|
|
let _ = validate_quantity(100.0);
|
|
let _ = validate_price(150.0);
|
|
}
|
|
})
|
|
});
|
|
|
|
futures::future::join_all(tasks).await;
|
|
})
|
|
},
|
|
);
|
|
}
|
|
|
|
group.finish();
|
|
}
|
|
|
|
/// Benchmark string operations
|
|
fn bench_string_operations(c: &mut Criterion) {
|
|
let mut group = c.benchmark_group("string_operations");
|
|
|
|
// Different string lengths for symbol generation
|
|
let prefixes = vec!["A", "TEST", "SYMBOL", "VERY_LONG_PREFIX"];
|
|
|
|
for prefix in prefixes {
|
|
group.bench_with_input(
|
|
BenchmarkId::new("symbol_formatting", prefix.len()),
|
|
&prefix,
|
|
|b, &p| {
|
|
b.iter(|| {
|
|
// Simulate symbol generation similar to TestUtilities::generate_test_symbol
|
|
let suffix = 1234u32;
|
|
let symbol = format!("{}{}", black_box(p), black_box(suffix));
|
|
black_box(symbol)
|
|
})
|
|
},
|
|
);
|
|
}
|
|
|
|
// String case conversion performance
|
|
let test_strings = vec!["buy", "sell", "MARKET", "limit", "new", "FILLED"];
|
|
|
|
for test_str in test_strings {
|
|
group.bench_with_input(
|
|
BenchmarkId::new("string_to_uppercase", test_str),
|
|
&test_str,
|
|
|b, &s| {
|
|
b.iter(|| {
|
|
let upper = s.to_uppercase();
|
|
black_box(upper)
|
|
})
|
|
},
|
|
);
|
|
}
|
|
|
|
group.finish();
|
|
}
|
|
|
|
/// Benchmark memory allocation patterns
|
|
fn bench_memory_allocation(c: &mut Criterion) {
|
|
let mut group = c.benchmark_group("memory_allocation");
|
|
|
|
// HashMap creation with different initial capacities
|
|
let capacities = vec![0, 10, 100, 1000];
|
|
|
|
for capacity in capacities {
|
|
group.bench_with_input(
|
|
BenchmarkId::new("hashmap_creation", capacity),
|
|
&capacity,
|
|
|b, &cap| {
|
|
b.iter(|| {
|
|
let mut map: HashMap<String, String> = HashMap::with_capacity(cap);
|
|
for i in 0..cap {
|
|
map.insert(format!("key_{}", i), format!("value_{}", i));
|
|
}
|
|
black_box(map)
|
|
})
|
|
},
|
|
);
|
|
}
|
|
|
|
// Vector creation and population
|
|
let sizes = vec![10, 100, 1000, 10000];
|
|
|
|
for size in sizes {
|
|
group.bench_with_input(BenchmarkId::new("vector_creation", size), &size, |b, &s| {
|
|
b.iter(|| {
|
|
let mut vec = Vec::with_capacity(s);
|
|
for i in 0..s {
|
|
vec.push(format!("item_{}", i));
|
|
}
|
|
black_box(vec)
|
|
})
|
|
});
|
|
}
|
|
|
|
group.finish();
|
|
}
|
|
|
|
/// Benchmark error handling performance
|
|
fn bench_error_handling(c: &mut Criterion) {
|
|
let mut group = c.benchmark_group("error_handling");
|
|
|
|
// Result creation and matching
|
|
group.bench_function("success_result", |b| {
|
|
b.iter(|| {
|
|
let result: FxtResult<i32> = Ok(black_box(42));
|
|
match result {
|
|
Ok(value) => black_box(value),
|
|
Err(_) => 0,
|
|
}
|
|
})
|
|
});
|
|
|
|
group.bench_function("error_result", |b| {
|
|
b.iter(|| {
|
|
let result: FxtResult<i32> = Err(FxtError::InvalidRequest("test error".to_string()));
|
|
match result {
|
|
Ok(value) => value,
|
|
Err(_) => black_box(0),
|
|
}
|
|
})
|
|
});
|
|
|
|
// Error creation
|
|
group.bench_function("error_creation", |b| {
|
|
b.iter(|| {
|
|
let error = FxtError::Connection(black_box("Connection failed".to_string()));
|
|
black_box(error)
|
|
})
|
|
});
|
|
|
|
// Error message formatting
|
|
group.bench_function("error_formatting", |b| {
|
|
let error = FxtError::InvalidSymbol("TEST".to_string());
|
|
b.iter(|| {
|
|
let formatted = format!("{}", black_box(&error));
|
|
black_box(formatted)
|
|
})
|
|
});
|
|
|
|
group.finish();
|
|
}
|
|
|
|
criterion_group!(
|
|
benches,
|
|
bench_timestamp_conversions,
|
|
bench_validation_operations,
|
|
bench_type_conversions,
|
|
bench_metric_creation,
|
|
bench_position_calculations,
|
|
bench_concurrent_validation,
|
|
bench_string_operations,
|
|
bench_memory_allocation,
|
|
bench_error_handling
|
|
);
|
|
|
|
criterion_main!(benches);
|
|
*/
|
|
|
|
// Placeholder to keep file valid
|
|
fn main() {
|
|
println!("Benchmark disabled - see file header for details");
|
|
}
|