Class: BenchmarkRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/tasks/benchmark_runner.rb

Defined Under Namespace

Modules: DataGenerator, Term

Constant Summary collapse

REPO_ROOT =
File.expand_path(File.join(__dir__, "..", ".."))
DEFAULT_RUN_TIME =

Benchmark configuration

5
DEFAULT_WARMUP =
2
DEFAULT_ITEMS =
50
CATEGORIES =

Category definitions with descriptions

{
  xml_parsing: {
    name: "XML Parsing",
    icon: "📄",
    description: "XML parsing performance tests. Measures how quickly we can convert XML strings into internal data structures.",
    failure_means: "Slow XML parsing impacts all downstream operations. A regression here means users will experience delays when processing XML documents.",
    compare_against: "Previous branch (main). We test both DOM parsing and SAX parsing.",
  },
  html_parsing: {
    name: "HTML Parsing",
    icon: "🌐",
    description: "HTML parsing for web scraping and document processing. Tests both simple and complex HTML with scripts/styles.",
    failure_means: "Slow HTML parsing affects web scraping workflows. Complex HTML tests include scripts and tables.",
    compare_against: "Previous branch (main).",
  },
  xml_comparison: {
    name: "XML Comparison",
    icon: "⚖️",
    description: "XML semantic comparison. Tests three scenarios: identical documents, similar documents, and documents with different namespaces.",
    failure_means: "Slow comparison means CI/CD pipelines and test suites will take longer. Critical for regression testing workflows.",
    compare_against: "Previous branch (main). Identical should be fastest, then similar, then different.",
  },
  html_comparison: {
    name: "HTML Comparison",
    icon: "🔍",
    description: "HTML semantic comparison. Tests HTML document equivalence including structural normalization.",
    failure_means: "Slow HTML comparison affects automated testing of web content. Critical for validation workflows.",
    compare_against: "Previous branch (main).",
  },
  formatting: {
    name: "Format Canonicalization",
    icon: "",
    description: "Format canonicalization (XML C14N, JSON, YAML). Tests how quickly we can produce canonical output from data structures.",
    failure_means: "Slow formatting affects serialization performance. C14N is critical for digital signatures and XML canonicalization.",
    compare_against: "Previous branch (main).",
  },
}.freeze
BENCHMARKS =

Test definitions

{
  xml_parsing: [
    { name: "DOM (simple)", method: :xml_parse_dom_simple,
      desc: "Standard DOM parsing" },
    { name: "SAX (simple)", method: :xml_parse_sax_simple,
      desc: "Streaming SAX parsing" },
    { name: "DOM (large)", method: :xml_parse_dom_large,
      desc: "Large document DOM" },
    { name: "SAX (large)", method: :xml_parse_sax_large,
      desc: "Large document SAX" },
  ],
  html_parsing: [
    { name: "Simple HTML", method: :html_parse_simple, desc: "Basic HTML" },
    { name: "Complex HTML", method: :html_parse_complex,
      desc: "HTML with scripts/tables" },
  ],
  xml_comparison: [
    { name: "Identical XML", method: :xml_compare_identical,
      desc: "Same documents" },
    { name: "Similar XML", method: :xml_compare_similar,
      desc: "Slightly different" },
    { name: "Different XML", method: :xml_compare_different,
      desc: "Different namespaces" },
  ],
  html_comparison: [
    { name: "Identical HTML", method: :html_compare_identical,
      desc: "Same HTML" },
    { name: "Similar HTML", method: :html_compare_similar,
      desc: "Slightly different" },
    { name: "Different HTML", method: :html_compare_different,
      desc: "Different structure" },
  ],
  formatting: [
    { name: "XML C14N", method: :xml_c14n_format, desc: "Canonical XML" },
    { name: "JSON", method: :json_format, desc: "JSON formatting" },
    { name: "YAML", method: :yaml_format, desc: "YAML formatting" },
  ],
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(run_time: nil, warmup: nil, items: nil, benchmark: nil) ⇒ BenchmarkRunner

Returns a new instance of BenchmarkRunner.



392
393
394
395
396
397
398
399
400
# File 'lib/tasks/benchmark_runner.rb', line 392

def initialize(run_time: nil, warmup: nil, items: nil, benchmark: nil)
  @run_time = run_time || DEFAULT_RUN_TIME
  @warmup = warmup || DEFAULT_WARMUP
  @items = items || DEFAULT_ITEMS
  @benchmark = benchmark
  @results = {}
  @env_shown = false
  @all_results = []
end

Instance Method Details

#run_benchmarksObject



402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
# File 'lib/tasks/benchmark_runner.rb', line 402

def run_benchmarks
  # Header
  Term.header("Canon Performance Benchmarks", color: Term::CYAN)

  unless @env_shown
    Term.env_info(RUBY_VERSION, RUBY_PLATFORM)
    @env_shown = true
  end

  # Run all categories
  BENCHMARKS.each do |category, tests|
    run_category(category, tests)
  end

  # Summary
  print_summary

  @results
end