/benchmark

Quality PERFORMANCE Production medium usage

/benchmark

Overview

The /benchmark command delivers comprehensive performance benchmarking with statistical rigor for the Prismatic Platform, providing P50/P95/P99/P999 percentile analysis, memory profiling, regression detection, and performance budget enforcement. Built on the Benchee benchmarking library, this command transforms performance validation from an ad-hoc activity into a systematic, reproducible, and enforceable quality gate that prevents performance regressions from reaching production.

Performance is a first-class concern in the Prismatic Platform, where the page load performance standard mandates sub-250ms total page loads and sub-100ms server-side render times with zero exceptions. The /benchmark command provides the measurement infrastructure that makes these standards enforceable. Rather than relying on intuition or manual profiling, it produces statistically valid performance measurements with controlled warmup periods, configurable iteration counts, and percentile analysis that accurately reflects production behavior at scale.

Operating under the PERFORMANCE authority level and executed by the performance-benchmarking-specialist agent, /benchmark is a production command in the Quality category of the platform's 216-command registry. It integrates directly with the platform's CI/CD pipeline as a mandatory deployment gate, ensuring that every release meets its performance budget before reaching production. The command has been battle-tested through the Wave 3 Performance Squad, where it validated 95-99.8% improvements across 11 critical operations with 100% budget compliance.

Usage

/benchmark [scope] [options]

The command accepts an optional scope parameter to target specific operation categories and a rich set of options for controlling benchmark execution, output, and enforcement behavior.

Examples

# Run the complete benchmark suite with defaults
/benchmark

# Benchmark specific operation categories
/benchmark cases
/benchmark --scope batch

# High-accuracy benchmarking with 500 iterations
/benchmark --iterations 500

# Budget compliance check only (faster, fewer iterations)
/benchmark --gate true --iterations 50

# Export results in JSON format for CI/CD integration
/benchmark --output json --save-baseline

# Regression analysis against a previous baseline
/benchmark --compare --baseline latest

# Full suite with HTML report generation
/benchmark --output all --time 15 --warmup 5

Options and Parameters

ParameterTypeRequiredDefaultDescription
scopestringNoallOperations to benchmark: cases, runs, ir-results, batch, api, database, storage, all
--categorystringNoallBenchmark category for budget level: critical, standard, exploratory, all
--iterationsintegerNo100Number of iterations for statistical accuracy
--timeintegerNo10Benchee execution time in seconds per scenario
--warmupintegerNo2Warmup time in seconds for JIT stabilization
--parallelintegerNo4Number of parallel benchmark processes
--memorybooleanNotrueEnable memory profiling and allocation tracking
--gatebooleanNofalseRun as quality gate (blocks on any budget violation)
--comparebooleanNofalseCompare results against a baseline
--baselinestringNolatestBaseline file or tag for regression analysis
--save-baselinebooleanNofalseSave current results as a new baseline
--outputstringNoallOutput format: console, html, markdown, json, all
--strictbooleanNotrueStrict budget enforcement (fail on any violation)
--regression-thresholdfloatNo0.05Regression threshold percentage (5% default)

Authority and Access

PropertyValue
Authority LevelPERFORMANCE
Executing Agentperformance-benchmarking-specialist
StatusProduction
Usage FrequencyMedium
CategoryQuality
Read AccessAll application code, performance baselines, budget configurations
Write AccessBenchmark results, baseline files, HTML/JSON/Markdown reports
Blocking AuthorityCan block deployments when run as quality gate (--gate true)
Support Agentsbackend-performance-engineer, database-core-specialist, benchmark-execution-specialist

Technical Implementation

The /benchmark command implements a multi-phase benchmarking pipeline built on Benchee, the Elixir benchmarking library. The pipeline progresses from environment initialization through benchmark execution to statistical analysis and budget compliance verification. Each phase is designed to produce statistically valid, reproducible results.

defmodule Prismatic.Commands.Benchmark do
  @moduledoc """
  AIAD-integrated Benchee performance validation with
  budget compliance and statistical rigor.
  """

  @performance_budgets %{
    case_list: %{budget_ms: 10, category: :critical},
    case_get: %{budget_ms: 2, category: :critical},
    case_create: %{budget_ms: 20, category: :critical},
    run_create: %{budget_ms: 10, category: :critical},
    ir_create: %{budget_ms: 5, category: :critical},
    ir_list: %{budget_ms: 8, category: :standard},
    batch_10: %{budget_ms: 20, category: :standard},
    batch_100: %{budget_ms: 100, category: :standard}
  }

  @spec execute(scope :: String.t(), opts :: keyword()) ::
          {:ok, BenchmarkReport.t()} | {:error, term()}
  def execute(scope \\ "all", opts \\ []) do
    iterations = Keyword.get(opts, :iterations, 100)
    time = Keyword.get(opts, :time, 10)

    with {:ok, config} <- load_benchee_config(scope, iterations, time, opts),
         {:ok, env} <- initialize_benchmark_environment(scope),
         {:ok, results} <- execute_benchee_scenarios(config, env),
         {:ok, stats} <- calculate_percentiles(results),
         {:ok, compliance} <- validate_budgets(stats, @performance_budgets),
         {:ok, regression} <- detect_regressions(stats, opts),
         {:ok, reports} <- generate_reports(stats, compliance, regression, opts) do
      {:ok, %{stats: stats, compliance: compliance, reports: reports}}
    end
  end
end

The benchmark execution uses realistic data volumes (100+ cases, 500+ runs) to ensure that measurements reflect production conditions. Warmup phases allow the BEAM VM's JIT to stabilize before measurements begin. Statistical analysis calculates min, max, average, median, standard deviation, and percentiles (P50, P95, P99, P999) for each operation. Budget compliance verification checks P95 latencies against predefined budgets with zero tolerance for critical operations.

Performance Budget Matrix

The following budgets are enforced with validated results from the Wave 3 Performance Squad:

OperationBudgetAchieved (Avg)Achieved (P95)Improvement
Case List10ms0.17ms0.20ms98.3%
Case Get2ms0.28ms0.35ms86.0%
Case Create20ms1.0ms1.25ms95.0%
Run Create10ms0.41ms0.52ms95.9%
IR Create5ms0.00ms0.01ms99.8%
IR List8ms0.23ms0.30ms97.1%
Batch 1020ms0.04ms0.06ms99.7%
Batch 100100ms0.39ms0.55ms99.5%

Workflow Integration

The /benchmark command integrates into multiple points in the development and deployment lifecycle. Its primary role is as a mandatory deployment gate, but it also serves as a development tool for performance optimization and a CI/CD component for regression prevention.

Common workflow patterns include:

  1. Pre-Deployment Gate: Run /benchmark --gate true --strict before every production deployment to enforce performance budgets
  2. Development Profiling: During optimization work, use /benchmark --scope [target] --iterations 500 for high-accuracy measurements of specific operations
  3. Regression Detection: After code changes, run /benchmark --compare --baseline latest to detect performance regressions against the most recent baseline
  4. Baseline Management: After performance improvements, run /benchmark --save-baseline to establish a new performance floor
  5. CI/CD Integration: Include /benchmark --gate true --output json in the GitLab CI pipeline to block merges that violate budgets
  6. Performance Reporting: Generate comprehensive reports with /benchmark --output all for stakeholder communication and audit trails

Integration Points

ComponentRelationship
Prismatic AgentsExecuted by performance-benchmarking-specialist agent
AIAD RegistryCommand specification and discovery
Quality GatesDirect quality gate enforcement with blocking authority
TelemetryCommand execution metrics and benchmark event tracking
Benchee LibraryCore benchmarking engine with statistical analysis
Performance BudgetsPredefined operation latency budgets with P95 enforcement
CI/CD PipelineMandatory gate in deployment workflow
Page Load Performance PolicyEnforces sub-250ms page load standard
Baseline StorageHistorical performance baselines for regression detection
Report GenerationHTML, Markdown, JSON output via Benchee formatters

Doctrine Compliance

All commands operate under the NO MERCY, NO DOUBTS doctrine:

  • NO MERCY: Performance budgets are absolute. Any operation that exceeds its P95 budget in strict mode causes immediate failure with a non-zero exit code. There are no grace periods, no acceptable degradation thresholds, and no exceptions. The command enforces 100% budget compliance on all critical operations. Regressions exceeding the configured threshold (default 5%) are treated as blocking violations.
  • NO DOUBTS: All performance claims are backed by statistical evidence. Measurements require a minimum of 100 iterations for statistical accuracy, with standard deviation ratio checks ensuring measurement reliability (std_dev_ratio < 25%). Results include percentile distributions, not just averages, because production performance is determined by tail latencies. Baselines provide objective comparison points that eliminate subjective assessment.
  • NABLA Compliance: Performance measurements satisfy signal plurality by aggregating multiple independent measurement runs (iterations) rather than relying on single observations. The statistical analysis surfaces contradictions between different percentile levels (e.g., good average but poor P99), preventing premature optimization conclusions. Time decay is enforced through baseline versioning, ensuring that performance comparisons use temporally relevant reference points.

Best Practices

  1. Always use sufficient iterations: The default 100 iterations provides good statistical accuracy; increase to 500+ for critical measurements or noisy environments
  2. Warm up before measuring: The default 2-second warmup is usually sufficient, but increase for benchmarks that involve database connections or external resources
  3. Save baselines after improvements: Whenever you make a validated performance improvement, save a new baseline with --save-baseline to ratchet the performance floor upward
  4. Use gate mode in CI: Always run with --gate true in CI pipelines to prevent performance regressions from reaching production
  5. Monitor P99, not just averages: Average performance can hide tail latency problems; always check P99 and P999 for operations that affect user experience
  6. Benchmark realistic data volumes: Use scopes that exercise realistic data volumes rather than trivial test datasets

Connect & Contribute

Created by Tomáš Korcak (korczis) | Open Source under GHL