benchkit 0.21.0

Lightweight benchmarking toolkit focused on practical performance analysis and report generation. Non-restrictive alternative to criterion, designed for easy integration and markdown report generation.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
//! Comprehensive benchkit integration with unilang_parser
//!
//! This demonstrates applying benchkit to parser performance analysis,
//! identifying parser-specific benchmarking needs and implementing solutions.

#![allow(clippy ::format_push_string)]
#![allow(clippy ::uninlined_format_args)]
#![allow(clippy ::std_instead_of_core)]
#![allow(clippy ::unnecessary_wraps)]
#![allow(clippy ::useless_format)]
#![allow(clippy ::redundant_closure_for_method_calls)]
#![allow(clippy ::cast_possible_truncation)]
#![allow(clippy ::cast_sign_loss)]
#![allow(clippy ::needless_borrows_for_generic_args)]
#![allow(clippy ::doc_markdown)]

use benchkit ::prelude :: *;

type Result< T > = std ::result ::Result< T, Box<dyn std ::error ::Error >>;

// We'll simulate unilang_parser functionality since it's in a different workspace
// In real integration, you'd use: use unilang_parser :: { Parser, UnilangParserOptions };

fn main() -> Result< () >
{
  println!("🚀 Benchkit Integration with unilang_parser");
  println!("============================================");
  println!();

  // Phase 1 : Parser-specific data generation
  test_parser_data_generation()?;
  
  // Phase 2 : Parsing performance analysis
  test_parsing_performance_analysis()?;
  
  // Phase 3 : Memory allocation in parsing pipeline  
  test_parser_memory_analysis()?;
  
  // Phase 4 : Parser throughput and scaling
  test_parser_throughput_analysis()?;
  
  // Phase 5 : Statistical validation of parser performance
  #[ cfg(feature = "statistical_analysis") ]
  test_parser_statistical_analysis()?;
  
  // Phase 6 : Parser-specific reporting
  test_parser_comprehensive_reporting()?;

  println!("✅ unilang_parser benchkit integration completed!");
  println!();
  
  // Identify missing benchkit features for parsers
  identify_parser_specific_features();
  
  Ok(())
}

fn test_parser_data_generation() -> Result< () >
{
  println!("1️⃣ Parser-Specific Data Generation");
  println!("---------------------------------");
  
  // Test command generation capabilities
  let command_generator = DataGenerator ::new()
  .complexity(DataComplexity ::Complex);
  
  let unilang_commands = command_generator.generate_unilang_commands(10);
  
  println!("  ✅ Generated {} unilang commands: ", unilang_commands.len());
  for (i, cmd) in unilang_commands.iter().take(3).enumerate() 
  {
  println!("     {}. {}", i + 1, cmd);
 }
  
  // Test parser-specific patterns
  println!("\n  📊 Parser-specific pattern generation: ");
  
  // Simple commands
  let simple_generator = DataGenerator ::new()
  .pattern("command{}.action{}")
  .repetitions(5)
  .complexity(DataComplexity ::Simple);
  let simple_commands = simple_generator.generate_string();
  println!("     Simple: {}", &simple_commands[..60.min(simple_commands.len())]);
  
  // Complex commands with arguments
  let complex_generator = DataGenerator ::new()
  .pattern("namespace{}.cmd{} arg{} ::value{} pos{}")
  .repetitions(3)
  .complexity(DataComplexity ::Complex);
  let complex_commands = complex_generator.generate_string();
  println!("     Complex: {}", &complex_commands[..80.min(complex_commands.len())]);
  
  // Nested command structures
  let nested_data = generate_nested_parser_commands(3, 4);
  println!("     Nested: {} chars generated", nested_data.len());
  
  println!();
  Ok(())
}

fn test_parsing_performance_analysis() -> Result< () >
{
  println!("2️⃣ Parser Performance Analysis");
  println!("-----------------------------");
  
  // Generate realistic parser test data
  let simple_cmd = "system.status";
  let medium_cmd = "user.create name ::alice email ::alice@test.com active ::true";
  let complex_cmd = "report.generate format ::pdf output :: \"/tmp/report.pdf\" compress ::true metadata :: \"Daily Report\" tags :: [\"daily\",\"automated\"] priority ::high";
  
  let simple_clone = simple_cmd.to_string();
  let medium_clone = medium_cmd.to_string();
  let complex_clone = complex_cmd.to_string();
  
  let mut parsing_comparison = ComparativeAnalysis ::new("unilang_parsing_performance");
  
  parsing_comparison = parsing_comparison
  .algorithm("simple_command", move || {
   let result = simulate_parse_command(&simple_clone);
   std ::hint ::black_box(result);
 })
  .algorithm("medium_command", move || {
   let result = simulate_parse_command(&medium_clone);
   std ::hint ::black_box(result);
 })
  .algorithm("complex_command", move || {
   let result = simulate_parse_command(&complex_clone);
   std ::hint ::black_box(result);
 });

  let parsing_report = parsing_comparison.run();
  
  if let Some((fastest, result)) = parsing_report.fastest()
  {
  println!("  ✅ Parsing performance analysis: ");
  println!("     - Fastest: {} ({:.0} parses/sec)", fastest, result.operations_per_second());
  println!("     - Reliability: CV = {:.1}%", result.coefficient_of_variation() * 100.0);
 }
  
  // Test batch parsing vs individual parsing
  println!("\n  📈 Batch vs Individual Parsing: ");
  
  let commands = vec![
  "system.status",
  "user.list active ::true",
  "log.rotate max_files :: 10",
  "cache.clear namespace ::temp",
  "db.backup name ::daily",
 ];
  
  let commands_clone = commands.clone();
  let commands_clone2 = commands.clone();
  
  let mut batch_comparison = ComparativeAnalysis ::new("batch_vs_individual_parsing");
  
  batch_comparison = batch_comparison
  .algorithm("individual_parsing", move || {
   let mut total_parsed = 0;
   for cmd in &commands_clone 
   {
  let _result = simulate_parse_command(cmd);
  total_parsed += 1;
 }
   std ::hint ::black_box(total_parsed);
 })
  .algorithm("batch_parsing", move || {
   let batch_input = commands_clone2.join(" ;; ");
   let result = simulate_batch_parse(&batch_input);
   std ::hint ::black_box(result);
 });

  let batch_report = batch_comparison.run();
  
  if let Some((fastest_batch, result)) = batch_report.fastest()
  {
  println!("     - Fastest approach: {} ({:.0} ops/sec)", fastest_batch, result.operations_per_second());
 }
  
  println!();
  Ok(())
}

fn test_parser_memory_analysis() -> Result< () >
{
  println!("3️⃣ Parser Memory Analysis");
  println!("------------------------");
  
  let memory_benchmark = MemoryBenchmark ::new("unilang_parser_memory");
  
  // Test memory usage patterns in parsing
  let complex_command = "system.process.management.service.restart name ::web_server graceful ::true timeout :: 30s force ::false backup_config ::true notify_admins :: [\"admin1@test.com\",\"admin2@test.com\"] log_level ::debug";
  
  let cmd_clone = complex_command.to_string();
  let cmd_clone2 = complex_command.to_string();
  
  let memory_comparison = memory_benchmark.compare_memory_usage(
  "string_based_parsing",
  move || {
   // Simulate string-heavy parsing (old approach)
   let parts = cmd_clone.split_whitespace().collect :: < Vec<_ >>();
   let tokens = parts.into_iter().map(|s| s.to_string()).collect :: < Vec<_ >>();
   std ::hint ::black_box(tokens.len());
 },
  "zero_copy_parsing", 
  move || {
   // Simulate zero-copy parsing (optimized approach)
   let parts = cmd_clone2.split_whitespace().collect :: < Vec<_ >>();
   std ::hint ::black_box(parts.len());
 },
  20,
 );
  
  let (efficient_name, efficient_stats) = memory_comparison.more_memory_efficient();
  let reduction = memory_comparison.memory_reduction_percentage();
  
  println!("  ✅ Parser memory analysis: ");
  println!("     - More efficient: {} ({:.1}% reduction)", efficient_name, reduction);
  println!("     - Peak memory: {} bytes", efficient_stats.peak_usage);
  println!("     - Total allocations: {}", efficient_stats.allocation_count);
  
  // Test allocation patterns during parsing pipeline
  println!("\n  🧠 Parsing pipeline allocation analysis: ");
  
  let mut profiler = MemoryProfiler ::new();
  
  // Simulate parsing pipeline stages
  profiler.record_allocation(1024); // Tokenization
  profiler.record_allocation(512);  // AST construction  
  profiler.record_allocation(256);  // Argument processing
  profiler.record_deallocation(256); // Cleanup temporaries
  profiler.record_allocation(128);  // Final instruction building
  
  let pattern_analysis = profiler.analyze_patterns();
  
  println!("     - Total allocation events: {}", pattern_analysis.total_events);
  println!("     - Peak usage: {} bytes", pattern_analysis.peak_usage);
  println!("     - Memory leaks detected: {}", if pattern_analysis.has_potential_leaks() { "Yes" } else { "No" });
  
  if let Some(size_stats) = pattern_analysis.size_statistics()
  {
  println!("     - Allocation sizes: min={}, max={}, avg={:.1}", 
  size_stats.min, size_stats.max, size_stats.mean);
 }
  
  println!();
  Ok(())
}

fn test_parser_throughput_analysis() -> Result< () >
{
  println!("4️⃣ Parser Throughput Analysis");  
  println!("----------------------------");
  
  // Generate realistic parser workload
  let parser_workload = generate_parser_workload(1000);
  println!("  📊 Generated parser workload: {} commands, {} total chars", 
   parser_workload.len(), 
   parser_workload.iter().map(|s| s.len()).sum :: < usize >());
  
  let total_chars = parser_workload.iter().map(|s| s.len()).sum :: < usize >();
  let throughput_analyzer = ThroughputAnalyzer ::new("parser_throughput", total_chars as u64)
  .with_items(parser_workload.len() as u64);
  
  // Simulate different parser implementations
  let mut parser_results = std ::collections ::HashMap ::new();
  
  // Fast parser (optimized)
  let fast_times = vec![std ::time ::Duration ::from_micros(50); 15];
  parser_results.insert("optimized_parser".to_string(), 
   BenchmarkResult ::new("optimized", fast_times));
  
  // Standard parser
  let standard_times = vec![std ::time ::Duration ::from_micros(150); 15];
  parser_results.insert("standard_parser".to_string(),
   BenchmarkResult ::new("standard", standard_times));
  
  // Naive parser (baseline)
  let naive_times = vec![std ::time ::Duration ::from_micros(400); 15];
  parser_results.insert("naive_parser".to_string(),
   BenchmarkResult ::new("naive", naive_times));
  
  let throughput_comparison = throughput_analyzer.compare_throughput(&parser_results);
  
  if let Some((fastest_name, fastest_metrics)) = throughput_comparison.fastest_throughput()
  {
  println!("  ✅ Parser throughput analysis: ");
  println!("     - Fastest parser: {} ({})", fastest_name, fastest_metrics.throughput_description());
  
  if let Some(items_desc) = fastest_metrics.items_description()
  {
   println!("     - Command parsing rate: {}", items_desc);
 }
 }
  
  if let Some(speedups) = throughput_comparison.calculate_speedups("naive_parser")
  {
  println!("     - Performance improvements: ");
  for (name, speedup) in speedups
  {
   if name != "naive_parser"
   {
  println!("       * {} : {:.1}x faster than baseline", name, speedup);
 }
 }
 }
  
  // Parser-specific throughput metrics
  println!("\n  📈 Parser-specific metrics: ");
  
  if let Some(fastest_metrics) = throughput_comparison.fastest_throughput().map(|(_, m)| m)
  {
  let chars_per_sec = (total_chars as f64 / fastest_metrics.processing_time.as_secs_f64()) as u64;
  let commands_per_sec = (parser_workload.len() as f64 / fastest_metrics.processing_time.as_secs_f64()) as u64;
  
  println!("     - Characters processed: {}/sec", format_throughput_number(chars_per_sec));
  println!("     - Commands parsed: {}/sec", format_throughput_number(commands_per_sec));
  println!("     - Average command size: {} chars", total_chars / parser_workload.len());
 }
  
  println!();
  Ok(())
}

#[ cfg(feature = "statistical_analysis") ]
fn test_parser_statistical_analysis() -> Result< () >
{
  println!("5️⃣ Parser Statistical Analysis");
  println!("-----------------------------");
  
  // Create parser performance data with different characteristics
  let consistent_parser_times: Vec< _ > = (0..25)
  .map(|i| std ::time ::Duration ::from_micros(100 + i * 2))
  .collect();
  let consistent_result = BenchmarkResult ::new("consistent_parser", consistent_parser_times);
  
  let variable_parser_times: Vec< _ > = (0..25)
  .map(|i| std ::time ::Duration ::from_micros(100 + (i * i) % 50))
  .collect();  
  let variable_result = BenchmarkResult ::new("variable_parser", variable_parser_times);
  
  // Analyze statistical properties
  let consistent_analysis = StatisticalAnalysis ::analyze(&consistent_result, SignificanceLevel ::Standard)?;
  let variable_analysis = StatisticalAnalysis ::analyze(&variable_result, SignificanceLevel ::Standard)?;
  
  println!("  ✅ Parser statistical analysis: ");
  println!("     - Consistent parser: ");
  println!("       * CV: {:.1}% ({})", 
   consistent_analysis.coefficient_of_variation * 100.0,
   if consistent_analysis.is_reliable() 
   { "✅ Reliable" } else { "⚠️ Questionable" });
  println!("       * 95% CI: [{:.1}, {:.1}] μs",
   consistent_analysis.mean_confidence_interval.lower_bound.as_micros(),
   consistent_analysis.mean_confidence_interval.upper_bound.as_micros());
  
  println!("     - Variable parser: ");
  println!("       * CV: {:.1}% ({})",
   variable_analysis.coefficient_of_variation * 100.0,
   if variable_analysis.is_reliable() 
   { "✅ Reliable" } else { "⚠️ Questionable" });
  println!("       * 95% CI: [{:.1}, {:.1}] μs",
   variable_analysis.mean_confidence_interval.lower_bound.as_micros(),
   variable_analysis.mean_confidence_interval.upper_bound.as_micros());
  
  // Statistical comparison
  let comparison = StatisticalAnalysis ::compare(
  &consistent_result,
  &variable_result,
  SignificanceLevel ::Standard
 )?;
  
  println!("  ✅ Statistical comparison: ");
  println!("     - Effect size: {:.3} ({})", 
   comparison.effect_size,
   comparison.effect_size_interpretation());
  println!("     - Statistically significant: {}", 
   if comparison.is_significant 
   { "✅ Yes" } else { "❌ No" });
  println!("     - P-value: {:.6}", comparison.p_value);
  
  // Parser performance reliability assessment
  println!("\n  📊 Parser reliability assessment: ");
  
  let reliability_threshold = 10.0; // 10% CV threshold for parsers
  let consistent_reliable = consistent_analysis.coefficient_of_variation * 100.0 < reliability_threshold;
  let variable_reliable = variable_analysis.coefficient_of_variation * 100.0 < reliability_threshold;
  
  println!("     - Reliability threshold: {}% CV", reliability_threshold);
  println!("     - Consistent parser meets standard: {}", if consistent_reliable { "" } else { "" });
  println!("     - Variable parser meets standard: {}", if variable_reliable { "" } else { "" });
  
  println!();
  Ok(())
}

fn test_parser_comprehensive_reporting() -> Result< () >
{
  println!("6️⃣ Parser Comprehensive Reporting");
  println!("--------------------------------");
  
  // Generate comprehensive parser benchmark suite
  let parser_workload = generate_parser_workload(500);
  
  let workload_clone = parser_workload.clone();
  let workload_clone2 = parser_workload.clone();
  let workload_clone3 = parser_workload.clone();
  let workload_clone4 = parser_workload.clone();
  
  let mut parser_suite = BenchmarkSuite ::new("unilang_parser_comprehensive");
  
  // Add parser-specific benchmarks
  parser_suite.benchmark("tokenization", move || {
  let mut token_count = 0;
  for cmd in &workload_clone 
  {
   token_count += cmd.split_whitespace().count();
 }
  std ::hint ::black_box(token_count);
 });
  
  parser_suite.benchmark("command_path_parsing", move || {
  let mut command_count = 0;
  for cmd in &workload_clone2 
  {
   // Simulate command path extraction
   if let Some(first_part) = cmd.split_whitespace().next() 
   {
  command_count += first_part.split('.').count();
 }
 }
  std ::hint ::black_box(command_count);
 });
  
  parser_suite.benchmark("argument_parsing", move || {
  let mut arg_count = 0;
  for cmd in &workload_clone3 
  {
   // Simulate argument parsing
   arg_count += cmd.matches(" :: ").count();
   arg_count += cmd.split_whitespace().count().saturating_sub(1);
 }
  std ::hint ::black_box(arg_count);
 });
  
  parser_suite.benchmark("full_parsing", move || {
  let mut parsed_count = 0;
  for cmd in &workload_clone4 
  {
   let _result = simulate_parse_command(cmd);
   parsed_count += 1;
 }
  std ::hint ::black_box(parsed_count);
 });

  let parser_results = parser_suite.run_analysis();
  let _parser_report = parser_results.generate_markdown_report();
  
  // Generate parser-specific comprehensive report
  let comprehensive_report = generate_parser_report(&parser_workload, &parser_results);

  // Create output directory if it doesn't exist
  std ::fs ::create_dir_all("target")?;

  // Save parser report (temporary file with hyphen prefix)
  let report_path = "target/-unilang_parser_benchkit_report.md";
  std ::fs ::write(report_path, comprehensive_report)?;
  
  println!("  ✅ Parser comprehensive reporting: ");
  println!("     - Report saved: {}", report_path);
  println!("     - Parser benchmarks: {} analyzed", parser_results.results.len());
  
  // Show parser-specific insights
  if let Some((fastest_stage, result)) = parser_results.results.iter()
  .max_by(|a, b| a.1.operations_per_second().partial_cmp(&b.1.operations_per_second()).unwrap()) 
  {
  println!("     - Fastest parsing stage: {} ({:.0} ops/sec)", fastest_stage, result.operations_per_second());
 }
  
  // Parser quality assessment
  let mut reliable_stages = 0;
  let total_stages = parser_results.results.len();
  
  for (stage, result) in &parser_results.results 
  {
  let is_reliable = result.is_reliable();
  if is_reliable { reliable_stages += 1; }
  
  let cv = result.coefficient_of_variation() * 100.0;
  let status = if is_reliable { "" } else { "⚠️" };
  
  println!("     - {} : {} (CV: {:.1}%)", stage, status, cv);
 }
  
  println!("     - Parser reliability: {}/{} stages meet standards", reliable_stages, total_stages);
  
  println!();
  Ok(())
}

fn identify_parser_specific_features()
{
  println!("🔍 Parser-Specific Features Identified for benchkit");
  println!("===================================================");
  println!();
  
  println!("💡 Missing Features Needed for Parser Benchmarking: ");
  println!();
  
  println!("1️⃣ **Parser Data Generation**");
  println!("   - Command syntax generators with realistic patterns");
  println!("   - Argument structure generation (positional, named, quoted)");
  println!("   - Nested command hierarchies");
  println!("   - Error case generation for parser robustness testing");
  println!("   - Batch command generation with separators");
  println!();
  
  println!("2️⃣ **Parser Performance Metrics**");
  println!("   - Commands per second (cmd/s) calculations");
  println!("   - Tokens per second processing rates");
  println!("   - Parse tree construction throughput");
  println!("   - Error handling performance impact");
  println!("   - Memory allocation per parse operation");
  println!();
  
  println!("3️⃣ **Parser-Specific Analysis**");
  println!("   - Tokenization vs parsing vs AST construction breakdown");
  println!("   - Command complexity impact analysis");
  println!("   - Argument count scaling characteristics");
  println!("   - Quoting/escaping performance overhead");
  println!("   - Batch vs individual parsing efficiency");
  println!();
  
  println!("4️⃣ **Parser Quality Metrics**");
  println!("   - Parse success rate tracking");
  println!("   - Error recovery performance");
  println!("   - Parser reliability under load");  
  println!("   - Memory leak detection in parsing pipeline");
  println!("   - Zero-copy optimization validation");
  println!();
  
  println!("5️⃣ **Parser Reporting Enhancements**");
  println!("   - Command pattern performance matrices");
  println!("   - Parser stage bottleneck identification");
  println!("   - Parsing throughput vs accuracy tradeoffs");
  println!("   - Comparative parser implementation analysis");
  println!("   - Real-world command distribution impact");
  println!();
  
  println!("6️⃣ **Integration Capabilities**");
  println!("   - AST validation benchmarks");
  println!("   - Parser configuration impact testing");
  println!("   - Error message generation performance");
  println!("   - Multi-threaded parsing coordination");
  println!("   - Stream parsing vs batch parsing analysis");
  println!();
  
  println!("🎯 **Implementation Priority: **");
  println!("   Phase 1 : Parser data generation and command syntax generators");
  println!("   Phase 2 : Parser-specific throughput metrics (cmd/s, tokens/s)");
  println!("   Phase 3 : Parsing pipeline stage analysis and bottleneck detection");
  println!("   Phase 4 : Parser reliability and quality metrics");
  println!("   Phase 5 : Advanced parser reporting and comparative analysis");
  println!();
}

// Helper functions for parser simulation and data generation

fn simulate_parse_command(command: &str) -> usize
{
  // Simulate parsing by counting tokens and operations
  let tokens = command.split_whitespace().count();
  let named_args = command.matches(" :: ").count();
  let quoted_parts = command.matches('"').count() / 2;
  
  // Simulate parsing work
  std ::thread ::sleep(std ::time ::Duration ::from_nanos(tokens as u64 * 100 + named_args as u64 * 200));
  
  tokens + named_args + quoted_parts
}

fn simulate_batch_parse(batch_input: &str) -> usize
{
  let commands = batch_input.split(" ;; ");
  let mut total_operations = 0;
  
  for cmd in commands 
  {
  total_operations += simulate_parse_command(cmd);
 }
  
  // Batch parsing has some efficiency benefits
  std ::thread ::sleep(std ::time ::Duration ::from_nanos(total_operations as u64 * 80));
  
  total_operations
}

fn generate_nested_parser_commands(depth: usize, width: usize) -> String
{
  let mut commands = Vec ::new();
  
  for i in 0..depth 
  {
  for j in 0..width 
  {
   let command = format!(
  "level{}.section{}.action{} param{} ::value{} flag{} ::true",
  i, j, (i + j) % 5, j, i + j, (i * j) % 3
 );
   commands.push(command);
 }
 }
  
  commands.join(" ;; ")
}

fn generate_parser_workload(count: usize) -> Vec< String >
{
  let patterns = [
  "simple.command",
  "user.create name ::test email ::test@example.com",
  "system.process.restart service ::web graceful ::true timeout :: 30",
  "report.generate format ::pdf output :: \"/tmp/report.pdf\" compress ::true",
  "backup.database name ::production exclude :: [\"logs\",\"temp\"] compress ::gzip",
  "notify.admin message :: \"System maintenance\" priority ::high channels :: [\"email\",\"slack\"]",
  "log.rotate path :: \"/var/log/app.log\" max_size :: 100MB keep :: 7 compress ::true",
  "security.scan target :: \"web_app\" depth ::full report ::detailed exclude :: [\"assets\"]",
 ];
  
  (0..count)
  .map(|i| {
   let base_pattern = patterns[i % patterns.len()];
   format!("{} seq :: {}", base_pattern, i)
 })
  .collect()
}

fn format_throughput_number(num: u64) -> String
{
  if num >= 1_000_000 
  {
  format!("{:.1}M", num as f64 / 1_000_000.0)
 } else  if num >= 1_000 
  {
  format!("{:.1}K", num as f64 / 1_000.0)
 } else {
  format!("{}", num)
 }
}

fn generate_parser_report(workload: &[ String], results: &SuiteResults) -> String
{
  let mut report = String ::new();
  
  report.push_str("# unilang_parser Benchkit Integration Report\n\n");
  report.push_str("*Generated with benchkit parser-specific analysis*\n\n");
  
  report.push_str("## Executive Summary\n\n");
  report.push_str("This report demonstrates comprehensive benchkit integration with unilang_parser, ");
  report.push_str("showcasing parser-specific performance analysis capabilities and identifying ");
  report.push_str("additional features needed for parser benchmarking.\n\n");
  
  report.push_str(&format!("**Parser Workload Configuration: **\n"));
  report.push_str(&format!("- Commands tested: {}\n", workload.len()));
  report.push_str(&format!("- Total characters: {}\n", workload.iter().map(|s| s.len()).sum :: < usize >()));
  report.push_str(&format!("- Average command length: {:.1} chars\n", 
   workload.iter().map(|s| s.len()).sum :: < usize >() as f64 / workload.len() as f64));
  report.push_str(&format!("- Parsing stages analyzed: {}\n\n", results.results.len()));
  
  report.push_str("## Parser Performance Results\n\n");
  let base_report = results.generate_markdown_report();
  report.push_str(&base_report.generate());
  
  report.push_str("## Parser-Specific Analysis\n\n");
  
  // Analyze parser stage performance
  if let Some((fastest_stage, fastest_result)) = results.results.iter()
  .max_by(|a, b| a.1.operations_per_second().partial_cmp(&b.1.operations_per_second()).unwrap())
  {
  report.push_str(&format!("**Fastest Parsing Stage** : {} ({:.0} ops/sec)\n\n", 
  fastest_stage, fastest_result.operations_per_second()));
 }
  
  // Parser reliability assessment
  let mut reliable_stages = 0;
  let total_stages = results.results.len();
  
  for (stage, result) in &results.results 
  {
  let is_reliable = result.is_reliable();
  if is_reliable { reliable_stages += 1; }
  
  let cv = result.coefficient_of_variation() * 100.0;
  let status = if is_reliable { "✅ Reliable" } else { "⚠️ Needs improvement" };
  
  report.push_str(&format!("- **{}** : {} (CV: {:.1}%, samples: {})\n",
  stage, status, cv, result.times.len()));
 }
  
  report.push_str(&format!("\n**Parser Reliability** : {}/{} stages meet reliability standards\n\n",
   reliable_stages, total_stages));
  
  report.push_str("## Parser-Specific Features Identified\n\n");
  report.push_str("### Missing benchkit Capabilities for Parsers\n\n");
  report.push_str("1. **Parser Data Generation** : Command syntax generators, argument patterns, error cases\n");
  report.push_str("2. **Parser Metrics** : Commands/sec, tokens/sec, parse tree throughput\n");
  report.push_str("3. **Pipeline Analysis** : Stage-by-stage performance breakdown\n");
  report.push_str("4. **Quality Metrics** : Success rates, error recovery, memory leak detection\n");
  report.push_str("5. **Parser Reporting** : Pattern matrices, bottleneck identification\n\n");
  
  report.push_str("## Integration Success\n\n");
  report.push_str("✅ **Parser benchmarking successfully integrated with benchkit**\n\n");
  report.push_str("**Key Achievements: **\n");
  report.push_str("- Comprehensive parser performance analysis\n");
  report.push_str("- Memory allocation tracking in parsing pipeline\n");
  report.push_str("- Statistical validation of parser performance\n");
  report.push_str("- Throughput analysis for parsing operations\n");
  report.push_str("- Professional parser benchmark reporting\n\n");
  
  report.push_str("**Recommendations: **\n");
  report.push_str("1. **Implement parser-specific data generators** for realistic command patterns\n");
  report.push_str("2. **Add parsing throughput metrics** (cmd/s, tokens/s) to benchkit\n");
  report.push_str("3. **Develop parser pipeline analysis** for bottleneck identification\n");
  report.push_str("4. **Integrate parser quality metrics** for reliability assessment\n");
  report.push_str("5. **Enhanced parser reporting** with command pattern analysis\n\n");
  
  report.push_str("---\n");
  report.push_str("*Report generated by benchkit parser integration analysis*\n");
  
  report
}