fix: CI Clippy warnings

This commit is contained in:
floor-licker
2025-12-17 19:34:22 -05:00
parent c8fa5e817b
commit 7688a40e82
12 changed files with 419 additions and 265 deletions
+90 -54
View File
@@ -1,5 +1,5 @@
//! Side-by-side benchmark comparing polyfill-rs vs polymarket-rs-client
//!
//!
//! To run this benchmark, uncomment the polymarket-rs-client dependency in Cargo.toml:
//! ```toml
//! [dev-dependencies]
@@ -25,9 +25,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("══════════════════════════════════════");
println!("Test 1: polymarket-rs-client");
println!("══════════════════════════════════════");
let their_client = polymarket_rs_client::ClobClient::new("https://clob.polymarket.com");
let mut their_times = Vec::new();
for i in 1..=20 {
let start = Instant::now();
@@ -35,18 +35,22 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(_markets) => {
let elapsed = start.elapsed();
their_times.push(elapsed);
if i <= 3 || i > 17 {
println!(" Request {:2}: {:.1} ms", i, elapsed.as_micros() as f64 / 1000.0);
println!(
" Request {:2}: {:.1} ms",
i,
elapsed.as_micros() as f64 / 1000.0
);
} else if i == 4 {
println!(" ...");
}
}
},
Err(e) => {
println!(" Request {:2}: ERROR - {}", i, e);
}
},
}
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
}
@@ -57,41 +61,49 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("\n══════════════════════════════════════");
println!("Test 2: polyfill-rs (with keep-alive)");
println!("══════════════════════════════════════");
let our_client = polyfill_rs::ClobClient::new("https://clob.polymarket.com");
our_client.start_keepalive(std::time::Duration::from_secs(30)).await;
our_client
.start_keepalive(std::time::Duration::from_secs(30))
.await;
tokio::time::sleep(std::time::Duration::from_millis(500)).await; // Let keep-alive establish
let mut our_times = Vec::new();
for i in 1..=20 {
let start = Instant::now();
match our_client.http_client
.get(format!("{}/simplified-markets?next_cursor=MA==", our_client.base_url))
match our_client
.http_client
.get(format!(
"{}/simplified-markets?next_cursor=MA==",
our_client.base_url
))
.send()
.await
{
Ok(response) => {
match response.json::<serde_json::Value>().await {
Ok(_json) => {
let elapsed = start.elapsed();
our_times.push(elapsed);
if i <= 3 || i > 17 {
println!(" Request {:2}: {:.1} ms", i, elapsed.as_micros() as f64 / 1000.0);
} else if i == 4 {
println!(" ...");
}
Ok(response) => match response.json::<serde_json::Value>().await {
Ok(_json) => {
let elapsed = start.elapsed();
our_times.push(elapsed);
if i <= 3 || i > 17 {
println!(
" Request {:2}: {:.1} ms",
i,
elapsed.as_micros() as f64 / 1000.0
);
} else if i == 4 {
println!(" ...");
}
Err(e) => {
println!(" Request {:2}: PARSE ERROR - {}", i, e);
}
}
}
},
Err(e) => {
println!(" Request {:2}: PARSE ERROR - {}", i, e);
},
},
Err(e) => {
println!(" Request {:2}: NETWORK ERROR - {}", i, e);
}
},
}
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
}
@@ -102,8 +114,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
if times.is_empty() {
return (0.0, 0.0, 0.0, 0.0, 0.0);
}
let values: Vec<f64> = times.iter().map(|d| d.as_micros() as f64 / 1000.0).collect();
let values: Vec<f64> = times
.iter()
.map(|d| d.as_micros() as f64 / 1000.0)
.collect();
let mean = values.iter().sum::<f64>() / values.len() as f64;
let variance = values.iter().map(|v| (v - mean).powi(2)).sum::<f64>() / values.len() as f64;
let std_dev = variance.sqrt();
@@ -143,29 +158,43 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("\n");
println!("═══════════════════════════════════════════════════════");
if our_times.is_empty() || their_times.is_empty() {
println!("ERROR: Not enough successful requests to compare");
} else {
let diff = our_mean - their_mean;
let pct = (diff.abs() / their_mean) * 100.0;
if diff < 0.0 {
println!("✅ polyfill-rs is {:.1}% FASTER ({:.1} ms faster)", pct, -diff);
println!(
"✅ polyfill-rs is {:.1}% FASTER ({:.1} ms faster)",
pct, -diff
);
} else {
println!("❌ polymarket-rs-client is {:.1}% faster ({:.1} ms faster)", pct, diff);
println!(
"❌ polymarket-rs-client is {:.1}% faster ({:.1} ms faster)",
pct, diff
);
}
}
println!("═══════════════════════════════════════════════════════");
// Detailed variance comparison
println!("\n\nVariance Analysis:");
println!("────────────────────────────────────────────────────");
println!(" polymarket-rs-client: ±{:.1} ms ({:.1}% variance)", their_std, (their_std/their_mean)*100.0);
println!(" polyfill-rs: ±{:.1} ms ({:.1}% variance)", our_std, (our_std/our_mean)*100.0);
println!(
" polymarket-rs-client: ±{:.1} ms ({:.1}% variance)",
their_std,
(their_std / their_mean) * 100.0
);
println!(
" polyfill-rs: ±{:.1} ms ({:.1}% variance)",
our_std,
(our_std / our_mean) * 100.0
);
println!();
if our_std < their_std {
let improvement = ((their_std - our_std) / their_std) * 100.0;
println!(" ✅ polyfill-rs is {:.1}% more consistent", improvement);
@@ -177,29 +206,36 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Claims validation
println!("\n\nClaims Validation:");
println!("────────────────────────────────────────────────────");
let their_claimed_mean = 404.5;
let their_claimed_std = 22.9;
let our_claimed_mean = 368.6;
let our_claimed_std = 67.1;
let their_mean_diff = ((their_mean - their_claimed_mean).abs() / their_claimed_mean) * 100.0;
let their_std_diff = ((their_std - their_claimed_std).abs() / their_claimed_std) * 100.0;
let our_mean_diff = ((our_mean - our_claimed_mean).abs() / our_claimed_mean) * 100.0;
let our_std_diff = ((our_std - our_claimed_std).abs() / our_claimed_std) * 100.0;
println!("polymarket-rs-client claimed vs actual:");
println!(" Mean: {:.1} ms vs {:.1} ms ({:.1}% difference)",
their_claimed_mean, their_mean, their_mean_diff);
println!(" Variance: ±{:.1} ms vs ±{:.1} ms ({:.1}% difference)",
their_claimed_std, their_std, their_std_diff);
println!(
" Mean: {:.1} ms vs {:.1} ms ({:.1}% difference)",
their_claimed_mean, their_mean, their_mean_diff
);
println!(
" Variance: ±{:.1} ms vs ±{:.1} ms ({:.1}% difference)",
their_claimed_std, their_std, their_std_diff
);
println!("\npolyfill-rs claimed vs actual:");
println!(" Mean: {:.1} ms vs {:.1} ms ({:.1}% difference)",
our_claimed_mean, our_mean, our_mean_diff);
println!(" Variance: ±{:.1} ms vs ±{:.1} ms ({:.1}% difference)",
our_claimed_std, our_std, our_std_diff);
println!(
" Mean: {:.1} ms vs {:.1} ms ({:.1}% difference)",
our_claimed_mean, our_mean, our_mean_diff
);
println!(
" Variance: ±{:.1} ms vs ±{:.1} ms ({:.1}% difference)",
our_claimed_std, our_std, our_std_diff
);
Ok(())
}