Skip to content

CLI Reference

Run benchmarks with powerful discovery and filtering options. The run command is the default and can be omitted.

Terminal window
# Run all benchmarks matching default pattern (./bench/**/*.bench.{js,mjs,cjs,ts})
modestbench
# Run all benchmarks in a directory (searches recursively)
modestbench benchmarks/
# Run specific files
modestbench benchmarks/critical.bench.js
# Run from multiple directories
modestbench src/perf/ tests/benchmarks/
# Mix files, directories, and glob patterns
modestbench file.bench.js benchmarks/ "tests/**/*.bench.ts"
# Explicit run command (optional)
modestbench run benchmarks/
  • JavaScript: .js, .mjs, .cjs
  • TypeScript: .ts, .mts, .cts

Specify a custom configuration file path.

Terminal window
modestbench --config ./custom-config.json

Number of samples to collect per benchmark task.

Terminal window
modestbench --iterations 5000

Higher values provide more accurate results but take longer to complete.

Time budget in milliseconds per benchmark task.

Terminal window
modestbench --time 10000

Control how benchmarks are limited. Options:

  • iterations - Stop after N samples (fast, predictable)
  • time - Run for T milliseconds (consistent time investment)
  • any - Stop when either threshold is reached (default when both specified)
  • all - Require both time AND iterations thresholds
Terminal window
# Explicit control
modestbench --iterations 500 --time 5000 --limit-by time
# Safety bounds (whichever comes first)
modestbench --iterations 1000 --time 10000 --limit-by any
# Statistical rigor (both required)
modestbench --iterations 100 --time 2000 --limit-by all

Smart Defaults:

  • Only --iterations → Uses iterations mode (fast)
  • Only --time → Uses time mode
  • Both specified → Uses any mode (whichever comes first)
  • Neither specified → Uses default iterations (100) with iterations mode

Number of warmup iterations before measurement begins.

Terminal window
modestbench --warmup 100

Helps stabilize JIT compilation for more consistent results.

Select the benchmark engine. Options: tinybench (default) or accurate.

Terminal window
# Use the accurate engine for high-precision measurements
node --allow-natives-syntax ./node_modules/.bin/modestbench --engine accurate
# Use tinybench engine (default)
modestbench --engine tinybench

Engine Differences:

  • tinybench (default): Fast, lightweight engine suitable for development and CI. Uses IQR-based outlier removal.
  • accurate: High-precision engine with V8 optimization guards to prevent JIT compiler interference. Requires --allow-natives-syntax flag. Recommended for production benchmarks and critical performance measurements.

See the Getting Started guide for detailed comparison.

Maximum time in milliseconds for a single task before timing out.

Terminal window
modestbench --timeout 60000

Default: 30000 (30 seconds)

Stop execution on first benchmark failure.

Terminal window
modestbench --bail

Useful in CI/CD to fail fast when performance regressions are detected.

Reporter to use for output. Can be specified multiple times.

Terminal window
# Single reporter
modestbench --reporter json
# Multiple reporters simultaneously
modestbench --reporter human --reporter json --reporter csv
# Using short alias
modestbench -r human -r json -r csv

Available reporters:

  • human - Color-coded terminal output (default for TTY with colors)
  • simple - Plain text output (default for non-TTY environments)
  • json - Structured JSON data
  • csv - Tabular CSV format

Directory path for saving benchmark results and reports.

Terminal window
modestbench --reporter json --reporter csv --output ./results

When specified:

  • JSON reporter writes to {output}/results.json
  • CSV reporter writes to {output}/results.csv
  • Human reporter still writes to stdout/stderr

Minimal output mode. Suppresses progress bars and non-essential messages.

Terminal window
modestbench --quiet

Detailed output mode with additional debugging information.

Terminal window
modestbench --verbose

Run only benchmarks with specific tags (OR logic - matches ANY). Can be specified multiple times.

Terminal window
# Single tag
modestbench --tag fast
# Multiple tags (matches ANY)
modestbench --tag string --tag array --tag algorithm
# Using short alias
modestbench -t string -t array

Tags cascade from file → suite → task levels. If a benchmark has ANY of the specified tags, it will run.

Exclude benchmarks with specific tags. Can be specified multiple times.

Terminal window
# Exclude one type
modestbench --exclude-tag slow
# Exclude multiple types
modestbench --exclude-tag experimental --exclude-tag unstable
# Using short alias
modestbench -e experimental -e unstable

Run benchmark files concurrently (experimental).

Terminal window
modestbench --concurrent
Terminal window
modestbench \
--config ./config.json \
--iterations 2000 \
--warmup 50 \
-r human \
-r json \
-r csv \
--output ./results \
-t performance \
-t algorithm \
-e experimental \
--quiet \
benchmarks/

Initialize a project with configuration and example benchmarks.

Terminal window
# Interactive initialization
modestbench init
# Specify project type
modestbench init basic
modestbench init advanced
modestbench init library
# Specify config format
modestbench init --config-type typescript
modestbench init --config-type json
modestbench init --config-type yaml
modestbench init --config-type js
  • basic - Simple setup for small projects

    • 100 iterations
    • Human reporter
    • Minimal configuration
  • advanced - Feature-rich setup

    • 1000 iterations
    • Warmup enabled
    • Human + JSON reporters
    • Organized suite structure
  • library - Optimized for library performance testing

    • 5000 iterations
    • High warmup (100)
    • Human + JSON reporters
    • Comprehensive suite organization
  1. Generates a configuration file in your chosen format
  2. Creates an example benchmark file
  3. Appends .modestbench/ to .gitignore to exclude historical data

Analyze code execution to identify hot paths and benchmark candidates. Uses Node.js V8 profiler to capture real execution data and focuses on your code (excluding node_modules and Node.js internals).

Terminal window
# Analyze a command
modestbench analyze "npm test"
# Analyze a script
modestbench analyze "node ./src/server.js"
# Analyze existing profile
modestbench analyze --input isolate-0x123-v8.log

The command to analyze (e.g., "npm test", "node script.js").

Terminal window
modestbench analyze "npm test"

Path to an existing V8 CPU profile file (*.cpuprofile).

Terminal window
modestbench analyze --input CPU.20231027.161625.89167.0.001.cpuprofile

Filter functions by file glob pattern. Useful for focusing on specific modules.

Terminal window
# Only show functions in utils
modestbench analyze "npm test" --filter-file "**/utils/**"
# Focus on specific files
modestbench analyze "npm test" --filter-file "**/src/core/**"

Minimum execution percentage to display (default: 0.5).

Terminal window
# Only show functions using ≥5% execution time
modestbench analyze "npm test" --min-percent 5.0

Number of top functions to show (default: 25).

Terminal window
# Show top 50 functions
modestbench analyze "npm test" --top 50
# Show top 10 only
modestbench analyze "npm test" -n 10

Group results by source file for a file-centric view.

Terminal window
modestbench analyze "npm test" --group-by-file

This groups functions by their source file and shows:

  • Total percentage for each file
  • Individual functions within each file
  • Line numbers for each function

Enable or disable colored output (auto-detected by default).

Terminal window
# Force colors
modestbench analyze "npm test" --color
# Disable colors
modestbench analyze "npm test" --no-color
Terminal window
modestbench analyze "npm test" \
--filter-file "**/src/**" \
--min-percent 2.0 \
--top 50 \
--group-by-file

The profiler displays results with color-coded percentages:

  • Red (≥10%): Critical hot paths - highest priority
  • Yellow (≥5%): Significant execution time
  • Cyan (≥2%): Moderate impact
  • White (<2%): Minor impact

Run existing test files as benchmarks. Captures test definitions from Jest, Mocha, node:test, or AVA test files and executes them as benchmark tasks.

Terminal window
# Run Jest tests as benchmarks
modestbench test jest "test/*.test.js"
# Run Mocha tests as benchmarks
modestbench test mocha "test/*.spec.js"
# Run node:test files as benchmarks
modestbench test node-test "test/*.test.js"
# Run AVA tests as benchmarks
modestbench test ava "test/*.js"
# Multiple patterns
modestbench test mocha "test/unit/*.spec.js" "test/integration/*.spec.js"
  • jest - Jest test files using describe/it/test syntax
  • mocha - Mocha test files using describe/it syntax
  • node-test - Node.js built-in test runner (node:test module)
  • ava - AVA test files

The test framework to use. Must be one of: jest, mocha, node-test, ava.

Test file paths or glob patterns.

Terminal window
modestbench test mocha "test/**/*.spec.js"

Number of iterations per test (default: 100).

Terminal window
modestbench test mocha test/*.spec.js --iterations 500

Number of warmup iterations before measurement (default: 5).

Terminal window
modestbench test mocha test/*.spec.js --warmup 10

Stop on first failure.

Terminal window
modestbench test mocha test/*.spec.js --bail

Output results in JSON format.

Terminal window
modestbench test mocha test/*.spec.js --json

Minimal output mode.

Terminal window
modestbench test mocha test/*.spec.js --quiet

The test command:

  1. Captures test definitions by intercepting the test framework’s API
  2. Converts test suites to benchmark suites and tests to benchmark tasks
  3. Preserves setup/teardown hooks (beforeEach/afterEach)
  4. Executes each test multiple times to collect timing statistics

Test hierarchy is preserved: describe blocks become benchmark suites, it/test blocks become benchmark tasks.

  • Quick performance checks - See how fast your tests actually run
  • Regression detection - Identify tests that have become slower over time
  • Optimization targets - Find slow tests that might benefit from optimization
  • CI integration - Add performance metrics to your test pipeline
Terminal window
# Basic Mocha benchmarking
modestbench test mocha "test/*.spec.js"
# node:test with more iterations
modestbench test node-test "test/*.test.js" --iterations 500
# AVA with JSON output for CI
modestbench test ava "test/*.js" --json --quiet
# Stop on first slow test
modestbench test mocha "test/unit/*.spec.js" --bail

Manage benchmark history and compare results over time.

List recent benchmark runs.

Terminal window
modestbench history list

Show detailed results for a specific run.

Terminal window
modestbench history show run-2025-10-07-001

Compare two benchmark runs.

Terminal window
modestbench history compare run-2025-10-07-001 run-2025-10-07-002

Export historical data.

Terminal window
# Export to CSV
modestbench history export --format csv --output results.csv
# Export to JSON
modestbench history export --format json --output results.json

Clean old benchmark data.

Terminal window
# Clean runs older than 30 days
modestbench history clean --older-than 30d
# Keep only last 10 runs
modestbench history clean --keep 10
# Clean by size
modestbench history clean --max-size 100mb

These options work with all commands:

Show help information.

Terminal window
modestbench --help
modestbench --help # shows run command help (default command)
modestbench history --help

Show version number.

Terminal window
modestbench --version

modestbench respects several environment variables:

Enable debug mode with detailed logging.

Terminal window
DEBUG=1 modestbench

Shows full error stack traces and additional debugging information.

Automatically detected CI environment flag.

Terminal window
CI=true modestbench

When detected:

  • Captures CI provider information
  • Stores build details in results
  • May adjust defaults for CI-friendly output

Node.js environment mode. Stored in benchmark results for context.

Terminal window
NODE_ENV=production modestbench

Control color output in terminal.

Terminal window
# Force color output
FORCE_COLOR=1 modestbench
# Disable color output
NO_COLOR=1 modestbench

Command-line flags override configuration file settings:

modestbench.config.json
{
"iterations": 1000,
"reporters": ["human"]
}
Terminal window
# CLI flags take precedence
modestbench --iterations 5000 --reporter json
# Result: iterations=5000, reporters=["json"]

Priority order:

  1. Default values (lowest)
  2. Configuration file
  3. CLI flags (highest)
Terminal window
modestbench --iterations 10 --quiet
Terminal window
modestbench \
--iterations 5000 \
--warmup 100 \
-r human \
-r json \
-r csv \
--output ./results
Terminal window
modestbench \
-r json \
-r csv \
--output ./benchmark-results \
--quiet \
--bail \
-t critical
Terminal window
# Run current benchmarks
modestbench --reporter json --output ./current
# Compare with baseline
modestbench history compare baseline-run-id $(modestbench history list --format json | jq -r '.[0].id')