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).",
  },
  by_line_rendering: {
    name: "By-Line Rendering",
    icon: "🖨️",
    description: "Verbose by_line diff rendering (enricher, line builder, formatters). Referees the #86 rendering lane.",
    failure_means: "Slow diff display affects developer-facing CLI output and CI failure reports.",
    compare_against: "Previous branch (main). Inputs: documents with scattered value differences.",
  },
  data_comparison: {
    name: "Data Comparison",
    icon: "🧮",
    description: "JSON and YAML semantic comparison. Both formats load through their engine gateways (yeptris/stdlib), so this referees engine choice.",
    failure_means: "Slow data comparison affects validation pipelines and test suites. A regression here can also signal an engine lane flip gone wrong.",
    compare_against: "Previous branch (main). Inputs are freshly generated (different values), so the comparison does real work.",
  },
}.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" },
  ],
  by_line_rendering: [
    { name: "XML", method: :by_line_render_xml, desc: "by_line XML render" },
  ],
  data_comparison: [
    { name: "JSON", method: :json_compare_equivalent,
      desc: "JSON equivalence" },
    { name: "YAML", method: :yaml_compare_equivalent,
      desc: "YAML equivalence" },
  ],
}.freeze

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of BenchmarkRunner.



419
420
421
422
423
424
425
426
427
# File 'lib/tasks/benchmark_runner.rb', line 419

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



429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
# File 'lib/tasks/benchmark_runner.rb', line 429

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