style: format perf_benchmark.rs with cargo fmt
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -146,7 +146,15 @@ fn insert_labels_batch(conn: &Connection, doc_id: i64, labels: &[&str]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Simulate OLD string building: format! + push_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);
|
let mut content = format!("[[Issue]] #{}: {}\nProject: {}\n", iid, title, project);
|
||||||
content.push_str(&format!("URL: {}\n", url));
|
content.push_str(&format!("URL: {}\n", url));
|
||||||
content.push_str(&format!("Labels: {}\n", labels));
|
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
|
/// 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 _;
|
use std::fmt::Write as _;
|
||||||
let mut content = format!("[[Issue]] #{}: {}\nProject: {}\n", iid, title, project);
|
let mut content = format!("[[Issue]] #{}: {}\nProject: {}\n", iid, title, project);
|
||||||
let _ = writeln!(content, "URL: {}", url);
|
let _ = writeln!(content, "URL: {}", url);
|
||||||
@@ -171,7 +187,14 @@ const LABEL_SETS: &[&[&str]] = &[
|
|||||||
&["feature", "frontend", "design", "ux"],
|
&["feature", "frontend", "design", "ux"],
|
||||||
&["bug", "database", "performance"],
|
&["bug", "database", "performance"],
|
||||||
&["docs", "api"],
|
&["docs", "api"],
|
||||||
&["infrastructure", "ci-cd", "devops", "monitoring", "alerting", "sre"],
|
&[
|
||||||
|
"infrastructure",
|
||||||
|
"ci-cd",
|
||||||
|
"devops",
|
||||||
|
"monitoring",
|
||||||
|
"alerting",
|
||||||
|
"sre",
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
#[test]
|
#[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;
|
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!("Individual INSERTs: {:?}", individual_elapsed);
|
||||||
println!("Batch INSERT: {:?}", batch_elapsed);
|
println!("Batch INSERT: {:?}", batch_elapsed);
|
||||||
println!("Speedup: {:.2}x", speedup);
|
println!("Speedup: {:.2}x", speedup);
|
||||||
@@ -241,7 +267,10 @@ fn bench_label_insert_individual_vs_batch() {
|
|||||||
.collect::<Result<Vec<_>, _>>()
|
.collect::<Result<Vec<_>, _>>()
|
||||||
.unwrap();
|
.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]
|
#[test]
|
||||||
@@ -250,8 +279,24 @@ fn bench_string_building_old_vs_new() {
|
|||||||
|
|
||||||
// Warm up
|
// Warm up
|
||||||
for _ in 0..100 {
|
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_old(
|
||||||
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");
|
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
|
// 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;
|
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!("format!+push_str: {:?}", old_elapsed);
|
||||||
println!("writeln!: {:?}", new_elapsed);
|
println!("writeln!: {:?}", new_elapsed);
|
||||||
println!("Speedup: {:.2}x", speedup);
|
println!("Speedup: {:.2}x", speedup);
|
||||||
println!();
|
println!();
|
||||||
|
|
||||||
// Verify correctness: both produce identical output
|
// Verify correctness: both produce identical output
|
||||||
let old = build_content_old(42, "Test", "group/proj", "[\"bug\"]", "opened", "alice", "https://example.com");
|
let old = build_content_old(
|
||||||
let new = build_content_new(42, "Test", "group/proj", "[\"bug\"]", "opened", "alice", "https://example.com");
|
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");
|
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 source_id = (i % 100) + 1;
|
||||||
let mut stmt = conn.prepare(sql).unwrap();
|
let mut stmt = conn.prepare(sql).unwrap();
|
||||||
let _hash: Option<String> = stmt
|
let _hash: Option<String> = 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();
|
.ok();
|
||||||
}
|
}
|
||||||
let uncached_elapsed = start.elapsed();
|
let uncached_elapsed = start.elapsed();
|
||||||
@@ -338,14 +404,19 @@ fn bench_prepare_vs_prepare_cached() {
|
|||||||
let source_id = (i % 100) + 1;
|
let source_id = (i % 100) + 1;
|
||||||
let mut stmt = conn.prepare_cached(sql).unwrap();
|
let mut stmt = conn.prepare_cached(sql).unwrap();
|
||||||
let _hash: Option<String> = stmt
|
let _hash: Option<String> = 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();
|
.ok();
|
||||||
}
|
}
|
||||||
let cached_elapsed = start.elapsed();
|
let cached_elapsed = start.elapsed();
|
||||||
|
|
||||||
let speedup = uncached_elapsed.as_nanos() as f64 / cached_elapsed.as_nanos() as f64;
|
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(): {:?}", uncached_elapsed);
|
||||||
println!("prepare_cached(): {:?}", cached_elapsed);
|
println!("prepare_cached(): {:?}", cached_elapsed);
|
||||||
println!("Speedup: {:.2}x", speedup);
|
println!("Speedup: {:.2}x", speedup);
|
||||||
|
|||||||
Reference in New Issue
Block a user