From f1cb45a1685272a2447ec22b4bcd4ead0d8ad01e Mon Sep 17 00:00:00 2001 From: Taylor Eernisse Date: Fri, 6 Feb 2026 08:49:53 -0500 Subject: [PATCH] style: format perf_benchmark.rs with cargo fmt Co-Authored-By: Claude Opus 4.6 --- tests/perf_benchmark.rs | 97 +++++++++++++++++++++++++++++++++++------ 1 file changed, 84 insertions(+), 13 deletions(-) diff --git a/tests/perf_benchmark.rs b/tests/perf_benchmark.rs index b212f9b..ae298cd 100644 --- a/tests/perf_benchmark.rs +++ b/tests/perf_benchmark.rs @@ -146,7 +146,15 @@ fn insert_labels_batch(conn: &Connection, doc_id: i64, labels: &[&str]) { } /// Simulate OLD string building: format! + push_str -fn build_content_old(iid: i64, title: &str, project: &str, labels: &str, state: &str, author: &str, url: &str) -> String { +fn build_content_old( + iid: i64, + title: &str, + project: &str, + labels: &str, + state: &str, + author: &str, + url: &str, +) -> String { let mut content = format!("[[Issue]] #{}: {}\nProject: {}\n", iid, title, project); content.push_str(&format!("URL: {}\n", url)); content.push_str(&format!("Labels: {}\n", labels)); @@ -156,7 +164,15 @@ fn build_content_old(iid: i64, title: &str, project: &str, labels: &str, state: } /// Simulate NEW string building: writeln! directly -fn build_content_new(iid: i64, title: &str, project: &str, labels: &str, state: &str, author: &str, url: &str) -> String { +fn build_content_new( + iid: i64, + title: &str, + project: &str, + labels: &str, + state: &str, + author: &str, + url: &str, +) -> String { use std::fmt::Write as _; let mut content = format!("[[Issue]] #{}: {}\nProject: {}\n", iid, title, project); let _ = writeln!(content, "URL: {}", url); @@ -171,7 +187,14 @@ const LABEL_SETS: &[&[&str]] = &[ &["feature", "frontend", "design", "ux"], &["bug", "database", "performance"], &["docs", "api"], - &["infrastructure", "ci-cd", "devops", "monitoring", "alerting", "sre"], + &[ + "infrastructure", + "ci-cd", + "devops", + "monitoring", + "alerting", + "sre", + ], ]; #[test] @@ -216,7 +239,10 @@ fn bench_label_insert_individual_vs_batch() { let speedup = individual_elapsed.as_nanos() as f64 / batch_elapsed.as_nanos() as f64; - println!("\n=== Label INSERT Benchmark ({} iterations) ===", iterations); + println!( + "\n=== Label INSERT Benchmark ({} iterations) ===", + iterations + ); println!("Individual INSERTs: {:?}", individual_elapsed); println!("Batch INSERT: {:?}", batch_elapsed); println!("Speedup: {:.2}x", speedup); @@ -241,7 +267,10 @@ fn bench_label_insert_individual_vs_batch() { .collect::, _>>() .unwrap(); - assert_eq!(individual_labels, batch_labels, "Both approaches must produce identical results"); + assert_eq!( + individual_labels, batch_labels, + "Both approaches must produce identical results" + ); } #[test] @@ -250,8 +279,24 @@ fn bench_string_building_old_vs_new() { // Warm up for _ in 0..100 { - let _ = build_content_old(42, "Fix authentication bug in login flow", "mygroup/myproject", "[\"bug\",\"auth\",\"critical\"]", "opened", "alice", "https://gitlab.example.com/mygroup/myproject/-/issues/42"); - let _ = build_content_new(42, "Fix authentication bug in login flow", "mygroup/myproject", "[\"bug\",\"auth\",\"critical\"]", "opened", "alice", "https://gitlab.example.com/mygroup/myproject/-/issues/42"); + let _ = build_content_old( + 42, + "Fix authentication bug in login flow", + "mygroup/myproject", + "[\"bug\",\"auth\",\"critical\"]", + "opened", + "alice", + "https://gitlab.example.com/mygroup/myproject/-/issues/42", + ); + let _ = build_content_new( + 42, + "Fix authentication bug in login flow", + "mygroup/myproject", + "[\"bug\",\"auth\",\"critical\"]", + "opened", + "alice", + "https://gitlab.example.com/mygroup/myproject/-/issues/42", + ); } // Benchmark OLD @@ -288,15 +333,34 @@ fn bench_string_building_old_vs_new() { let speedup = old_elapsed.as_nanos() as f64 / new_elapsed.as_nanos() as f64; - println!("\n=== String Building Benchmark ({} iterations) ===", iterations); + println!( + "\n=== String Building Benchmark ({} iterations) ===", + iterations + ); println!("format!+push_str: {:?}", old_elapsed); println!("writeln!: {:?}", new_elapsed); println!("Speedup: {:.2}x", speedup); println!(); // Verify correctness: both produce identical output - let old = build_content_old(42, "Test", "group/proj", "[\"bug\"]", "opened", "alice", "https://example.com"); - let new = build_content_new(42, "Test", "group/proj", "[\"bug\"]", "opened", "alice", "https://example.com"); + let old = build_content_old( + 42, + "Test", + "group/proj", + "[\"bug\"]", + "opened", + "alice", + "https://example.com", + ); + let new = build_content_new( + 42, + "Test", + "group/proj", + "[\"bug\"]", + "opened", + "alice", + "https://example.com", + ); assert_eq!(old, new, "Both approaches must produce identical strings"); } @@ -327,7 +391,9 @@ fn bench_prepare_vs_prepare_cached() { let source_id = (i % 100) + 1; let mut stmt = conn.prepare(sql).unwrap(); let _hash: Option = stmt - .query_row(rusqlite::params!["issue", source_id as i64], |row| row.get(0)) + .query_row(rusqlite::params!["issue", source_id as i64], |row| { + row.get(0) + }) .ok(); } let uncached_elapsed = start.elapsed(); @@ -338,14 +404,19 @@ fn bench_prepare_vs_prepare_cached() { let source_id = (i % 100) + 1; let mut stmt = conn.prepare_cached(sql).unwrap(); let _hash: Option = stmt - .query_row(rusqlite::params!["issue", source_id as i64], |row| row.get(0)) + .query_row(rusqlite::params!["issue", source_id as i64], |row| { + row.get(0) + }) .ok(); } let cached_elapsed = start.elapsed(); let speedup = uncached_elapsed.as_nanos() as f64 / cached_elapsed.as_nanos() as f64; - println!("\n=== prepare vs prepare_cached Benchmark ({} iterations) ===", iterations); + println!( + "\n=== prepare vs prepare_cached Benchmark ({} iterations) ===", + iterations + ); println!("prepare(): {:?}", uncached_elapsed); println!("prepare_cached(): {:?}", cached_elapsed); println!("Speedup: {:.2}x", speedup);