#[test]
fn test_imp_194b_bench_suite_result() {
let config = BenchSuiteConfig::new("inference", true, 300);
let success = BenchSuiteResult::success(config.clone(), 45.5);
assert_eq!(
success.status,
BenchSuiteStatus::Success,
"IMP-194b: Should be success"
);
assert!(success.meets_qa041, "IMP-194b: Success should meet QA-041");
let failed = BenchSuiteResult::failed(config.clone(), "Assertion failed");
assert_eq!(
failed.status,
BenchSuiteStatus::Failed,
"IMP-194b: Should be failed"
);
assert!(
!failed.meets_qa041,
"IMP-194b: Failed should not meet QA-041"
);
println!("\nIMP-194b: Bench Suite Results:");
println!(
" Success: status={:?}, duration={:.1}s",
success.status, success.duration_secs
);
println!(
" Failed: status={:?}, error={:?}",
failed.status, failed.output
);
}
#[test]
fn test_imp_194c_skipped_optional() {
let optional = BenchSuiteConfig::new("gpu", true, 60).optional();
let required = BenchSuiteConfig::new("cpu", true, 60);
let optional_skip = BenchSuiteResult::skipped(optional, "GPU not available");
assert!(
optional_skip.meets_qa041,
"IMP-194c: Optional skip should meet QA-041"
);
let required_skip = BenchSuiteResult::skipped(required, "Dependency missing");
assert!(
!required_skip.meets_qa041,
"IMP-194c: Required skip should not meet QA-041"
);
println!("\nIMP-194c: Skipped Suites:");
println!(" Optional: meets_qa041={}", optional_skip.meets_qa041);
println!(" Required: meets_qa041={}", required_skip.meets_qa041);
}
#[test]
#[ignore = "Requires make bench-inference-all target"]
fn test_imp_194d_realworld_bench_inference_all() {
let suites = vec![
BenchSuiteConfig::new("tensor_ops", true, 60),
BenchSuiteConfig::new("inference", true, 120),
BenchSuiteConfig::new("cache", true, 60),
BenchSuiteConfig::new("tokenizer", true, 30),
];
let all_pass = suites.iter().all(|s| s.enabled);
println!("\nIMP-194d: Real-World Bench Inference All:");
for suite in &suites {
println!(
" {}: enabled={}, timeout={}s",
suite.name, suite.enabled, suite.timeout_secs
);
}
println!(" QA-041: {}", if all_pass { "PASS" } else { "FAIL" });
}
#[derive(Debug)]
pub struct FrameworkComparison {
pub framework_a: String,
pub framework_b: String,
pub metric: String,
pub value_a: f64,
pub value_b: f64,
pub ratio: f64,
pub winner: String,
}
impl FrameworkComparison {
pub fn new(
framework_a: &str,
framework_b: &str,
metric: &str,
value_a: f64,
value_b: f64,
) -> Self {
let ratio = if value_b > 0.0 {
value_a / value_b
} else {
f64::INFINITY
};
let winner = if value_a < value_b {
framework_a.to_string()
} else {
framework_b.to_string()
};
Self {
framework_a: framework_a.to_string(),
framework_b: framework_b.to_string(),
metric: metric.to_string(),
value_a,
value_b,
ratio,
winner,
}
}
}
#[derive(Debug)]
pub struct ComparisonReport {
pub comparisons: Vec<FrameworkComparison>,
pub generated_at: String,
pub meets_qa042: bool,
}
impl ComparisonReport {
pub fn new(comparisons: Vec<FrameworkComparison>) -> Self {
Self {
comparisons,
generated_at: chrono::Utc::now().to_rfc3339(),
meets_qa042: true,
}
}
pub fn summary(&self) -> String {
let mut summary = String::new();
for comp in &self.comparisons {
summary.push_str(&format!(
"{}: {} ({:.2}) vs {} ({:.2}) -> winner: {}\n",
comp.metric,
comp.framework_a,
comp.value_a,
comp.framework_b,
comp.value_b,
comp.winner
));
}
summary
}
}
#[test]
fn test_imp_195a_framework_comparison() {
let comp = FrameworkComparison::new("realizar", "pytorch", "latency_ms", 100.0, 150.0);
assert_eq!(
comp.winner, "realizar",
"IMP-195a: Lower latency should win"
);
assert!(
comp.ratio < 1.0,
"IMP-195a: Ratio should be < 1 when A is better"
);
let throughput = FrameworkComparison::new("realizar", "pytorch", "throughput", 143.0, 100.0);
println!("\nIMP-195a: Framework Comparison:");
println!(
" Latency: {} vs {} -> winner={}",
comp.value_a, comp.value_b, comp.winner
);
println!(
" Throughput: {} vs {}",
throughput.value_a, throughput.value_b
);
}
#[test]
fn test_imp_195b_comparison_report() {
let comparisons = vec![
FrameworkComparison::new("realizar", "pytorch", "latency_p50", 100.0, 120.0),
FrameworkComparison::new("realizar", "pytorch", "latency_p99", 150.0, 200.0),
];
let report = ComparisonReport::new(comparisons);
assert_eq!(
report.comparisons.len(),
2,
"IMP-195b: Should have 2 comparisons"
);
assert!(report.meets_qa042, "IMP-195b: Should meet QA-042");
assert!(
!report.generated_at.is_empty(),
"IMP-195b: Should have timestamp"
);
let summary = report.summary();
assert!(
summary.contains("latency_p50"),
"IMP-195b: Summary should contain metrics"
);
println!("\nIMP-195b: Comparison Report:");
println!("{}", summary);
}
#[test]
fn test_imp_195c_report_generation() {
let empty_report = ComparisonReport::new(Vec::new());
assert!(
empty_report.meets_qa042,
"IMP-195c: Empty report still meets QA-042"
);
let summary = empty_report.summary();
assert!(
summary.is_empty(),
"IMP-195c: Empty report should have empty summary"
);
println!("\nIMP-195c: Report Generation:");
println!(" Empty report: meets_qa042={}", empty_report.meets_qa042);
}
#[test]
#[ignore = "Requires PyTorch benchmark"]
fn test_imp_195d_realworld_pytorch_comparison() {
let comparisons = vec![
FrameworkComparison::new("realizar", "pytorch", "latency_p50_ms", 100.0, 120.0),
FrameworkComparison::new("realizar", "pytorch", "latency_p95_ms", 130.0, 180.0),
FrameworkComparison::new("realizar", "pytorch", "latency_p99_ms", 150.0, 250.0),
FrameworkComparison::new("realizar", "pytorch", "throughput_toks", 143.0, 100.0),
];
let report = ComparisonReport::new(comparisons);
println!("\nIMP-195d: Real-World PyTorch Comparison:");
println!("{}", report.summary());
println!("Generated: {}", report.generated_at);
println!(
"QA-042: {}",
if report.meets_qa042 { "PASS" } else { "FAIL" }
);
}
#[derive(Debug, Clone, PartialEq)]
pub enum CpuBackend {
Scalar,
Sse2,
Avx2,
Avx512,
Neon,
Wasm,
}
#[derive(Debug)]
pub struct CpuBackendResult {
pub backend: CpuBackend,
pub available: bool,
pub tested: bool,
pub throughput: Option<f64>,
pub meets_qa043: bool,
}
impl CpuBackendResult {
pub fn tested(backend: CpuBackend, throughput: f64) -> Self {
Self {
backend,
available: true,
tested: true,
throughput: Some(throughput),
meets_qa043: true,
}
}
pub fn unavailable(backend: CpuBackend) -> Self {
Self {
backend,
available: false,
tested: false,
throughput: None,
meets_qa043: true, }
}
pub fn skipped(backend: CpuBackend) -> Self {
Self {
backend,
available: true,
tested: false,
throughput: None,
meets_qa043: false, }
}
}
pub struct CpuBenchSuite {
pub backends: Vec<CpuBackend>,
}
impl Default for CpuBenchSuite {
fn default() -> Self {
Self {
backends: vec![
CpuBackend::Scalar,
CpuBackend::Sse2,
CpuBackend::Avx2,
CpuBackend::Avx512,
CpuBackend::Neon,
],
}
}
}
impl CpuBenchSuite {
pub fn detect_available(&self) -> Vec<CpuBackend> {
let mut available = vec![CpuBackend::Scalar];
#[cfg(target_arch = "x86_64")]
{
if is_x86_feature_detected!("sse2") {
available.push(CpuBackend::Sse2);
}
if is_x86_feature_detected!("avx2") {
available.push(CpuBackend::Avx2);
}
if is_x86_feature_detected!("avx512f") {
available.push(CpuBackend::Avx512);
}
}
#[cfg(target_arch = "aarch64")]
{
available.push(CpuBackend::Neon);
}
available
}
}
#[test]
fn test_imp_196a_cpu_backend_result() {
let tested = CpuBackendResult::tested(CpuBackend::Avx2, 143.0);
assert!(tested.tested, "IMP-196a: Should be tested");
assert!(
tested.throughput.is_some(),
"IMP-196a: Should have throughput"
);
assert!(tested.meets_qa043, "IMP-196a: Tested should meet QA-043");
let unavailable = CpuBackendResult::unavailable(CpuBackend::Avx512);
assert!(!unavailable.available, "IMP-196a: Should be unavailable");
assert!(
unavailable.meets_qa043,
"IMP-196a: Unavailable should meet QA-043"
);
let skipped = CpuBackendResult::skipped(CpuBackend::Sse2);
assert!(
!skipped.meets_qa043,
"IMP-196a: Skipped available should not meet QA-043"
);
println!("\nIMP-196a: CPU Backend Results:");
println!(
" Tested: {:?}, throughput={:?}",
tested.backend, tested.throughput
);
println!(
" Unavailable: {:?}, meets_qa043={}",
unavailable.backend, unavailable.meets_qa043
);
println!(
" Skipped: {:?}, meets_qa043={}",
skipped.backend, skipped.meets_qa043
);
}
#[test]
fn test_imp_196b_backend_detection() {
let suite = CpuBenchSuite::default();
let available = suite.detect_available();
assert!(
available.contains(&CpuBackend::Scalar),
"IMP-196b: Scalar always available"
);
assert!(
!available.is_empty(),
"IMP-196b: Should have at least one backend"
);
println!("\nIMP-196b: Backend Detection:");
println!(" Available backends: {:?}", available);
}
#[test]
fn test_imp_196c_backend_enumeration() {
let all_backends = vec![
CpuBackend::Scalar,
CpuBackend::Sse2,
CpuBackend::Avx2,
CpuBackend::Avx512,
CpuBackend::Neon,
CpuBackend::Wasm,
];
assert_eq!(
all_backends.len(),
6,
"IMP-196c: Should have 6 backend types"
);
println!("\nIMP-196c: All CPU Backends:");
for backend in all_backends {
println!(" {:?}", backend);
}
}