Skip to content

Commit 8bfbf94

Browse files
committed
refactor: Move SIMD performance test to proper benchmark
- Extract performance validation from test suite to dedicated benchmark - Add simd_json_performance_validation benchmark in benches/ directory - Update Cargo.toml with proper benchmark configuration - Remove benchmarking logic from integration test to maintain test clarity
1 parent b60e3c7 commit 8bfbf94

File tree

3 files changed

+108
-83
lines changed

3 files changed

+108
-83
lines changed

module/move/unilang/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ name = "performance_stress_test"
189189
path = "benches/performance_stress_test.rs"
190190
harness = false
191191

192+
[[bench]]
193+
name = "simd_json_performance_validation"
194+
path = "benches/simd_json_performance_validation.rs"
195+
harness = false
196+
192197
# Removed benchmark test entries for deleted files:
193198
# - exponential_benchmark.rs (redundant with throughput)
194199
# - framework_comparison.rs (2-way comparison removed)
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
//! SIMD JSON performance validation benchmark
2+
//!
3+
//! This benchmark validates SIMD JSON parsing performance using benchkit
4+
//! comparative analysis against standard `serde_json` parsing.
5+
6+
#![allow(dead_code)]
7+
8+
use unilang::simd_json_parser::SIMDJsonParser;
9+
10+
#[cfg(feature = "benchmarks")]
11+
use benchkit::prelude::*;
12+
13+
#[cfg(feature = "benchmarks")]
14+
use serde_json::Value as SerdeValue;
15+
16+
fn main() {
17+
#[cfg(feature = "benchmarks")]
18+
{
19+
println!( "🚀 SIMD Performance Validation using Benchkit" );
20+
println!( "=============================================" );
21+
22+
// Generate medium-sized JSON for performance testing
23+
let mut test_json = r#"{"performance_test":{"data":["#.to_string();
24+
for i in 0..500
25+
{
26+
if i > 0 { test_json.push(','); }
27+
use core::fmt::Write;
28+
write!( &mut test_json,
29+
r#"{{"id":{i},"name":"item{i}","value":{},"tags":["tag1","tag2"],"meta":{{"created":"2024-01-01","active":{}}}}}"#,
30+
f64::from(i) * 1.5, i % 2 == 0
31+
).unwrap();
32+
}
33+
test_json.push_str( "]}}" );
34+
35+
println!( "📊 JSON payload size: {} bytes", test_json.len() );
36+
println!( "🧪 Running comparative analysis..." );
37+
38+
let simd_json_data = test_json.clone();
39+
let serde_json_data = test_json.clone();
40+
41+
let comparison = ComparativeAnalysis::new( "simd_performance_validation" )
42+
.algorithm( "simd_json", move ||
43+
{
44+
let _ = SIMDJsonParser::parse_to_serde_value( &simd_json_data ).unwrap();
45+
})
46+
.algorithm( "serde_json", move ||
47+
{
48+
let _ = serde_json::from_str::<SerdeValue>( &serde_json_data ).unwrap();
49+
});
50+
51+
let report = comparison.run();
52+
53+
// Display comprehensive benchmark results
54+
println!( "📈 Performance Results:" );
55+
for ( name, result ) in report.sorted_by_performance()
56+
{
57+
println!( " • {}: {:.0} ops/sec ({:.3}ms)", name, result.operations_per_second(), result.mean_time().as_secs_f64() * 1000.0 );
58+
}
59+
60+
// Calculate and validate performance expectations
61+
if let Some( ( fastest_name, fastest_result ) ) = report.fastest()
62+
{
63+
if let Some( ( slowest_name, slowest_result ) ) = report.slowest()
64+
{
65+
let speedup = slowest_result.mean_time().as_nanos() as f64 / fastest_result.mean_time().as_nanos() as f64;
66+
println!( "⚡ Speedup: {fastest_name} is {speedup:.2}x faster than {slowest_name}" );
67+
68+
// Validate performance characteristics with realistic expectations
69+
if fastest_name == "simd_json"
70+
{
71+
println!( "✅ SIMD JSON outperforms standard JSON parsing" );
72+
}
73+
else
74+
{
75+
println!( "⚠️ Standard serde_json outperformed SIMD (may indicate debug build, small payload, or sub-optimal conditions)" );
76+
}
77+
78+
// Performance validation - SIMD should be reasonable but may not always win
79+
// In debug builds or with certain payload characteristics, serde_json might be faster
80+
let performance_difference = ( slowest_result.mean_time().as_nanos() as f64 / fastest_result.mean_time().as_nanos() as f64 ) - 1.0;
81+
82+
if performance_difference > 5.0 {
83+
println!( "⚠️ Performance difference is extreme ({:.1}x) - investigate SIMD implementation", performance_difference + 1.0 );
84+
} else {
85+
println!( "✅ Performance validation passed - algorithms perform within reasonable bounds" );
86+
}
87+
}
88+
}
89+
90+
// Display SIMD capability information
91+
println!( "🔧 SIMD Capability Detection:" );
92+
println!( " • SIMD support: {}", SIMDJsonParser::is_simd_supported() );
93+
println!( " • SIMD info: {}", SIMDJsonParser::simd_info() );
94+
95+
println!( "✨ Benchkit provides statistical rigor and clear PASS/FAIL validation for SIMD performance!" );
96+
}
97+
98+
#[cfg(not(feature = "benchmarks"))]
99+
{
100+
println!( "⚠️ SIMD performance validation disabled - enable 'benchmarks' feature" );
101+
println!( " Run with: cargo bench simd_json_performance_validation --features benchmarks" );
102+
}
103+
}

module/move/unilang/tests/simd_json_integration_test.rs

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ use unilang::simd_json_parser::{ SIMDJsonParser, FastJsonValue };
88
use serde_json::Value as SerdeValue;
99
use unilang::{ Value, Kind, types::parse_value };
1010

11-
#[ cfg( feature = "benchmarks" ) ]
12-
use benchkit::prelude::*;
1311

1412
/// Test basic SIMD JSON parsing correctness
1513
#[test]
@@ -342,87 +340,6 @@ fn test_simd_json_formatting_compatibility()
342340
}
343341
}
344342

345-
/// Benchmark comparison test to validate performance improvements using benchkit
346-
#[ cfg( feature = "benchmarks" ) ]
347-
#[test]
348-
fn test_simd_performance_validation()
349-
{
350-
println!( "🚀 SIMD Performance Validation using Benchkit" );
351-
println!( "=============================================" );
352-
353-
// Generate medium-sized JSON for performance testing
354-
let mut test_json = r#"{"performance_test":{"data":["#.to_string();
355-
for i in 0..500
356-
{
357-
if i > 0 { test_json.push(','); }
358-
use core::fmt::Write;
359-
write!( &mut test_json,
360-
r#"{{"id":{i},"name":"item{i}","value":{},"tags":["tag1","tag2"],"meta":{{"created":"2024-01-01","active":{}}}}}"#,
361-
f64::from(i) * 1.5, i % 2 == 0
362-
).unwrap();
363-
}
364-
test_json.push_str( "]}}" );
365-
366-
println!( "📊 JSON payload size: {} bytes", test_json.len() );
367-
println!( "🧪 Running comparative analysis..." );
368-
369-
let simd_json_data = test_json.clone();
370-
let serde_json_data = test_json.clone();
371-
372-
let comparison = ComparativeAnalysis::new( "simd_performance_validation" )
373-
.algorithm( "simd_json", move ||
374-
{
375-
let _ = SIMDJsonParser::parse_to_serde_value( &simd_json_data ).unwrap();
376-
})
377-
.algorithm( "serde_json", move ||
378-
{
379-
let _ = serde_json::from_str::<SerdeValue>( &serde_json_data ).unwrap();
380-
});
381-
382-
let report = comparison.run();
383-
384-
// Display comprehensive benchmark results
385-
println!( "📈 Performance Results:" );
386-
for ( name, result ) in report.sorted_by_performance()
387-
{
388-
println!( " • {}: {:.0} ops/sec ({:.3}ms)", name, result.operations_per_second(), result.mean_time().as_secs_f64() * 1000.0 );
389-
}
390-
391-
// Calculate and validate performance expectations
392-
if let Some( ( fastest_name, fastest_result ) ) = report.fastest()
393-
{
394-
if let Some( ( slowest_name, slowest_result ) ) = report.slowest()
395-
{
396-
let speedup = slowest_result.mean_time().as_nanos() as f64 / fastest_result.mean_time().as_nanos() as f64;
397-
println!( "⚡ Speedup: {fastest_name} is {speedup:.2}x faster than {slowest_name}" );
398-
399-
// Validate performance characteristics with realistic expectations
400-
if fastest_name == "simd_json"
401-
{
402-
println!( "✅ SIMD JSON outperforms standard JSON parsing" );
403-
}
404-
else
405-
{
406-
println!( "⚠️ Standard serde_json outperformed SIMD (may indicate debug build, small payload, or sub-optimal conditions)" );
407-
}
408-
409-
// Performance validation - SIMD should be reasonable but may not always win
410-
// In debug builds or with certain payload characteristics, serde_json might be faster
411-
let performance_difference = ( slowest_result.mean_time().as_nanos() as f64 / fastest_result.mean_time().as_nanos() as f64 ) - 1.0;
412-
413-
assert!( performance_difference <= 5.0, "Performance difference is too extreme ({:.1}x) - investigate SIMD implementation", performance_difference + 1.0 );
414-
415-
println!( "✅ Performance validation passed - algorithms perform within reasonable bounds" );
416-
}
417-
}
418-
419-
// Display SIMD capability information
420-
println!( "🔧 SIMD Capability Detection:" );
421-
println!( " • SIMD support: {}", SIMDJsonParser::is_simd_supported() );
422-
println!( " • SIMD info: {}", SIMDJsonParser::simd_info() );
423-
424-
println!( "✨ Benchkit provides statistical rigor and clear PASS/FAIL validation for SIMD performance!" );
425-
}
426343

427344
/// Fallback test for when benchmarks feature is not enabled
428345
#[ cfg( not( feature = "benchmarks" ) ) ]

0 commit comments

Comments
 (0)