impl E2EComparisonResult {
pub fn new(realizar_tps: f64, ollama_tps: f64, llamacpp_tps: f64) -> Self {
let gap_vs_ollama = if ollama_tps > 0.0 {
((realizar_tps - ollama_tps) / ollama_tps) * 100.0
} else {
0.0
};
let gap_vs_llamacpp = if llamacpp_tps > 0.0 {
((realizar_tps - llamacpp_tps) / llamacpp_tps) * 100.0
} else {
0.0
};
let parity_achieved = gap_vs_llamacpp >= -10.0;
Self {
realizar_tps,
ollama_tps,
llamacpp_tps,
gap_vs_ollama_percent: gap_vs_ollama,
gap_vs_llamacpp_percent: gap_vs_llamacpp,
parity_achieved,
timestamp: chrono::Utc::now().to_rfc3339(),
}
}
}
#[test]
fn test_imp_152a_e2e_comparison_struct() {
let result = E2EComparisonResult::new(200.0, 143.0, 256.0);
let expected_ollama_gap: f64 = ((200.0 - 143.0) / 143.0) * 100.0; let expected_llamacpp_gap: f64 = ((200.0 - 256.0) / 256.0) * 100.0;
assert!(
(result.gap_vs_ollama_percent - expected_ollama_gap).abs() < 0.1,
"IMP-152a: Ollama gap should be ~39.9%"
);
assert!(
(result.gap_vs_llamacpp_percent - expected_llamacpp_gap).abs() < 0.1,
"IMP-152a: llama.cpp gap should be ~-21.9%"
);
assert!(
!result.parity_achieved,
"IMP-152a: -21.9% gap should not be parity"
);
println!("\nIMP-152a: E2E Comparison Result:");
println!(" Realizar: {:.1} tok/s", result.realizar_tps);
println!(" Ollama: {:.1} tok/s", result.ollama_tps);
println!(" llama.cpp: {:.1} tok/s", result.llamacpp_tps);
println!(" Gap vs Ollama: {:+.1}%", result.gap_vs_ollama_percent);
println!(
" Gap vs llama.cpp: {:+.1}%",
result.gap_vs_llamacpp_percent
);
println!(" Parity achieved: {}", result.parity_achieved);
}
#[test]
fn test_imp_152b_parity_detection() {
let at_parity = E2EComparisonResult::new(232.0, 143.0, 256.0);
assert!(
at_parity.parity_achieved,
"IMP-152b: 232 vs 256 should be parity (-9.4%)"
);
let beyond_parity = E2EComparisonResult::new(260.0, 143.0, 256.0);
assert!(
beyond_parity.parity_achieved,
"IMP-152b: 260 vs 256 should definitely be parity"
);
assert!(
beyond_parity.gap_vs_llamacpp_percent > 0.0,
"IMP-152b: 260 vs 256 should show positive gap"
);
let below_parity = E2EComparisonResult::new(200.0, 143.0, 256.0);
assert!(
!below_parity.parity_achieved,
"IMP-152b: 200 vs 256 should NOT be parity"
);
let exact_threshold = E2EComparisonResult::new(231.0, 143.0, 256.0);
assert!(
exact_threshold.parity_achieved,
"IMP-152b: 231 vs 256 should be parity (-9.8%)"
);
println!("\nIMP-152b: Parity Detection:");
println!(
" 232 vs 256 = {:.1}% gap, parity={}",
at_parity.gap_vs_llamacpp_percent, at_parity.parity_achieved
);
println!(
" 260 vs 256 = {:+.1}% gap, parity={}",
beyond_parity.gap_vs_llamacpp_percent, beyond_parity.parity_achieved
);
println!(
" 200 vs 256 = {:.1}% gap, parity={}",
below_parity.gap_vs_llamacpp_percent, below_parity.parity_achieved
);
println!(
" 231 vs 256 = {:.1}% gap, parity={}",
exact_threshold.gap_vs_llamacpp_percent, exact_threshold.parity_achieved
);
}
#[test]
#[ignore = "Requires running Ollama (11434) and llama.cpp (8082) servers"]
fn test_imp_152c_real_e2e_comparison() {
let config = HttpBenchmarkConfig {
cv_criterion: CvStoppingCriterion::new(5, 20, 0.10),
warmup_iterations: 2,
prompt: "What is the capital of France? Answer in one word:".to_string(),
max_tokens: 20,
temperature: 0.0,
run_preflight: true,
filter_outliers: true,
outlier_k_factor: 3.0,
};
let mut runner = HttpBenchmarkRunner::new(config);
let llamacpp_result = runner
.benchmark_llamacpp("http://127.0.0.1:8082")
.expect("IMP-152c: llama.cpp benchmark failed");
let ollama_result = runner
.benchmark_ollama("http://127.0.0.1:11434", "phi2:2.7b")
.expect("IMP-152c: Ollama benchmark failed");
let realizar_tps: f64 = 61.0;
let comparison = E2EComparisonResult::new(
realizar_tps,
ollama_result.throughput_tps,
llamacpp_result.throughput_tps,
);
println!("\nIMP-152c: Real-World E2E Comparison:");
println!(" Realizar: {:.1} tok/s (test)", comparison.realizar_tps);
println!(" Ollama: {:.1} tok/s (measured)", comparison.ollama_tps);
println!(
" llama.cpp: {:.1} tok/s (measured)",
comparison.llamacpp_tps
);
println!(
" Gap vs Ollama: {:+.1}%",
comparison.gap_vs_ollama_percent
);
println!(
" Gap vs llama.cpp: {:+.1}%",
comparison.gap_vs_llamacpp_percent
);
println!(" Parity achieved: {}", comparison.parity_achieved);
println!(" Timestamp: {}", comparison.timestamp);
}
#[derive(Debug, Clone)]
pub struct ProgressDelta {
pub previous_tps: f64,
pub current_tps: f64,
pub delta_tps: f64,
pub delta_percent: f64,
pub next_milestone_tps: f64,
pub progress_to_next: f64,
}
impl ProgressDelta {
pub fn new(previous_tps: f64, current_tps: f64, next_milestone_tps: f64) -> Self {
let delta_tps = current_tps - previous_tps;
let delta_percent = if previous_tps > 0.0 {
(delta_tps / previous_tps) * 100.0
} else {
0.0
};
let progress_to_next = if next_milestone_tps > current_tps {
((current_tps - previous_tps) / (next_milestone_tps - previous_tps)) * 100.0
} else {
100.0 };
Self {
previous_tps,
current_tps,
delta_tps,
delta_percent,
next_milestone_tps,
progress_to_next,
}
}
}
#[test]
fn test_imp_152d_progress_delta_tracking() {
let delta = ProgressDelta::new(80.0, 100.0, 120.0);
assert!(
(delta.delta_tps - 20.0).abs() < 0.01,
"IMP-152d: Delta should be 20 tok/s"
);
assert!(
(delta.delta_percent - 25.0).abs() < 0.1,
"IMP-152d: Delta should be 25%"
);
assert!(
(delta.progress_to_next - 50.0).abs() < 0.1,
"IMP-152d: Progress should be 50% (20 of 40 tok/s needed)"
);
let delta2 = ProgressDelta::new(100.0, 120.0, 200.0);
assert!(
(delta2.delta_percent - 20.0).abs() < 0.1,
"IMP-152d: Delta should be 20%"
);
let delta3 = ProgressDelta::new(180.0, 210.0, 200.0);
assert!(
(delta3.progress_to_next - 100.0).abs() < 0.01,
"IMP-152d: Should be 100% when beyond milestone"
);
println!("\nIMP-152d: Progress Delta Tracking:");
println!(
" 80 โ 100 (target 120): {:+.0} tok/s ({:+.1}%), {:.0}% to milestone",
delta.delta_tps, delta.delta_percent, delta.progress_to_next
);
println!(
" 100 โ 120 (target 200): {:+.0} tok/s ({:+.1}%), {:.0}% to milestone",
delta2.delta_tps, delta2.delta_percent, delta2.progress_to_next
);
println!(
" 180 โ 210 (target 200): {:+.0} tok/s ({:+.1}%), {:.0}% to milestone",
delta3.delta_tps, delta3.delta_percent, delta3.progress_to_next
);
}