fix: resolve rustfmt configuration duplicate key error and apply consistent code formatting across all source files

This commit is contained in:
floor-licker
2025-12-05 19:09:06 -05:00
parent 5576d765ee
commit 9993e51c7f
29 changed files with 2540 additions and 1673 deletions
+95 -61
View File
@@ -5,13 +5,13 @@ use std::time::Instant;
async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("🚀 Simple Network Benchmark - polyfill-rs");
println!("==========================================");
let client = ClobClient::new("https://clob.polymarket.com");
// Test 1: Server Time (baseline network latency)
println!("\n📊 Test 1: Server Time (Network Baseline)");
println!("=========================================");
let mut times = Vec::new();
for i in 0..10 {
let start = Instant::now();
@@ -20,52 +20,54 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let duration = start.elapsed();
times.push(duration);
if i < 3 {
println!(" Run {}: ✅ {} in {:?}", i+1, timestamp, duration);
println!(" Run {}: ✅ {} in {:?}", i + 1, timestamp, duration);
}
}
},
Err(e) => {
let duration = start.elapsed();
times.push(duration);
println!(" Run {}: ❌ Error in {:?}: {}", i+1, duration, e);
}
println!(" Run {}: ❌ Error in {:?}: {}", i + 1, duration, e);
},
}
}
if !times.is_empty() {
let avg = times.iter().sum::<std::time::Duration>() / times.len() as u32;
let min = times.iter().min().unwrap();
let max = times.iter().max().unwrap();
println!(" 📈 Average: {:?}", avg);
println!(" 📊 Range: {:?} - {:?}", min, max);
println!(" 🌐 Network baseline: ~{:?}", min);
}
// Test 2: Market Data (comparable to original benchmarks)
println!("\n📊 Test 2: Market Data Fetching");
println!("===============================");
println!("Target: polymarket-rs-client 404.5ms ± 22.9ms");
// Try different endpoints to see which ones work
let endpoints = vec![
("Simplified Markets", "get_sampling_simplified_markets"),
("Full Markets", "get_sampling_markets"),
("Market Prices", "get_prices_batch"),
];
for (name, _method) in endpoints {
println!("\n 🔍 Testing {}:", name);
let mut times = Vec::new();
for i in 0..5 {
let start = Instant::now();
let result = match name {
"Simplified Markets" => {
client.get_sampling_simplified_markets(None).await.map(|r| r.data.len())
}
"Full Markets" => {
client.get_sampling_markets(None).await.map(|r| r.data.len())
}
"Simplified Markets" => client
.get_sampling_simplified_markets(None)
.await
.map(|r| r.data.len()),
"Full Markets" => client
.get_sampling_markets(None)
.await
.map(|r| r.data.len()),
"Market Prices" => {
// Try with some example BookParams
let book_params = vec![
@@ -75,96 +77,116 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}
];
client.get_prices(&book_params).await.map(|r| r.len())
}
},
_ => continue,
};
let duration = start.elapsed();
times.push(duration);
match result {
Ok(count) => {
if i < 2 {
println!(" Run {}: ✅ {} items in {:?}", i+1, count, duration);
println!(" Run {}: ✅ {} items in {:?}", i + 1, count, duration);
}
}
},
Err(e) => {
if i < 2 {
println!(" Run {}: ❌ Error in {:?}: {}", i+1, duration, e);
println!(" Run {}: ❌ Error in {:?}: {}", i + 1, duration, e);
}
}
},
}
}
if !times.is_empty() {
let avg = times.iter().sum::<std::time::Duration>() / times.len() as u32;
let min = times.iter().min().unwrap();
let max = times.iter().max().unwrap();
let std_dev = {
let mean = avg.as_millis() as f64;
let variance = times.iter()
let variance = times
.iter()
.map(|t| (t.as_millis() as f64 - mean).powi(2))
.sum::<f64>() / times.len() as f64;
.sum::<f64>()
/ times.len() as f64;
variance.sqrt()
};
println!(" 📈 polyfill-rs: {:.1}ms ± {:.1}ms", avg.as_millis(), std_dev);
println!(
" 📈 polyfill-rs: {:.1}ms ± {:.1}ms",
avg.as_millis(),
std_dev
);
println!(" 📊 Range: {:?} - {:?}", min, max);
if name == "Simplified Markets" {
println!(" 🆚 vs original (404.5ms): {:.1}x {}",
404.5 / avg.as_millis() as f64,
if avg.as_millis() < 405 { "faster" } else { "slower" });
println!(
" 🆚 vs original (404.5ms): {:.1}x {}",
404.5 / avg.as_millis() as f64,
if avg.as_millis() < 405 {
"faster"
} else {
"slower"
}
);
}
}
}
// Test 3: Computational Performance (our strength)
println!("\n📊 Test 3: Computational Performance");
println!("===================================");
use polyfill_rs::OrderBookImpl;
use rust_decimal::Decimal;
use std::str::FromStr;
let mut book = OrderBookImpl::new("test_token".to_string(), 100);
// Populate the book first
for i in 0..100 {
let price = Decimal::from_str(&format!("0.{:04}", 5000 + i)).unwrap();
let size = Decimal::from_str("100.0").unwrap();
let delta = polyfill_rs::OrderDelta {
token_id: "test_token".to_string(),
timestamp: chrono::Utc::now(),
side: if i % 2 == 0 { polyfill_rs::Side::BUY } else { polyfill_rs::Side::SELL },
side: if i % 2 == 0 {
polyfill_rs::Side::BUY
} else {
polyfill_rs::Side::SELL
},
price,
size,
sequence: i as u64,
};
let _ = book.apply_delta(delta);
}
// Benchmark order book updates
let start = Instant::now();
for i in 0..10000 {
let price = Decimal::from_str(&format!("0.{:04}", 5000 + (i % 1000))).unwrap();
let size = Decimal::from_str("100.0").unwrap();
let delta = polyfill_rs::OrderDelta {
token_id: "test_token".to_string(),
timestamp: chrono::Utc::now(),
side: if i % 2 == 0 { polyfill_rs::Side::BUY } else { polyfill_rs::Side::SELL },
side: if i % 2 == 0 {
polyfill_rs::Side::BUY
} else {
polyfill_rs::Side::SELL
},
price,
size,
sequence: (i + 1000) as u64,
};
let _ = book.apply_delta(delta);
}
let book_duration = start.elapsed();
// Benchmark fast calculations
let start = Instant::now();
for _ in 0..1000000 {
@@ -172,17 +194,23 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let _ = book.mid_price_fast();
}
let calc_duration = start.elapsed();
println!(" ⚡ Order book: 10,000 updates in {:?}", book_duration);
println!(" 📊 Rate: {:.0} updates/second", 10000.0 / book_duration.as_secs_f64());
println!(
" 📊 Rate: {:.0} updates/second",
10000.0 / book_duration.as_secs_f64()
);
println!(" ⚡ Fast calcs: 2M operations in {:?}", calc_duration);
println!(" 📊 Rate: {:.0}M operations/second", 2.0 / calc_duration.as_secs_f64());
println!(
" 📊 Rate: {:.0}M operations/second",
2.0 / calc_duration.as_secs_f64()
);
// Test 4: JSON Parsing Performance
println!("\n📊 Test 4: JSON Parsing Performance");
println!("==================================");
let sample_market_json = r#"{
"condition_id": "21742633143463906290569050155826241533067272736897614950488156847949938836455",
"question": "Will Donald Trump win the 2024 US Presidential Election?",
@@ -213,35 +241,41 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}
]
}"#;
let start = Instant::now();
for _ in 0..10000 {
let _: Result<serde_json::Value, _> = serde_json::from_str(sample_market_json);
}
let json_duration = start.elapsed();
println!(" ⚡ JSON parsing: 10,000 parses in {:?}", json_duration);
println!(" 📊 Rate: {:.0} parses/second", 10000.0 / json_duration.as_secs_f64());
println!(" 📊 Per parse: {:.1}µs", json_duration.as_micros() as f64 / 10000.0);
println!(
" 📊 Rate: {:.0} parses/second",
10000.0 / json_duration.as_secs_f64()
);
println!(
" 📊 Per parse: {:.1}µs",
json_duration.as_micros() as f64 / 10000.0
);
println!("\n🎯 Summary");
println!("=========");
println!("Network Performance:");
println!(" • Competitive with polymarket-rs-client baseline");
println!(" • Network latency dominates end-to-end performance");
println!(" • Geographic location affects results significantly");
println!("\nComputational Performance:");
println!(" • Order book operations: Sub-millisecond");
println!(" • Fast calculations: Sub-microsecond");
println!(" • JSON parsing: Microsecond-scale");
println!(" • Memory efficient: Zero-allocation hot paths");
println!("\n✨ polyfill-rs provides:");
println!(" • Same network performance as alternatives");
println!(" • Superior computational performance");
println!(" • Memory-optimized data structures");
println!(" • Fixed-point arithmetic advantages");
Ok(())
}