CLI Reference
Commands
Section titled “Commands”modestbench [pattern..]
Section titled “modestbench [pattern..]”Run benchmarks with powerful discovery and filtering options. The run command is the default and can be omitted.
Basic Usage
Section titled “Basic Usage”# 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 filesmodestbench benchmarks/critical.bench.js
# Run from multiple directoriesmodestbench src/perf/ tests/benchmarks/
# Mix files, directories, and glob patternsmodestbench file.bench.js benchmarks/ "tests/**/*.bench.ts"
# Explicit run command (optional)modestbench run benchmarks/Supported File Extensions
Section titled “Supported File Extensions”- JavaScript:
.js,.mjs,.cjs - TypeScript:
.ts,.mts,.cts
Options
Section titled “Options”--config <path>
Section titled “--config <path>”Specify a custom configuration file path.
modestbench --config ./custom-config.json--iterations <number>
Section titled “--iterations <number>”Number of samples to collect per benchmark task.
modestbench --iterations 5000Higher values provide more accurate results but take longer to complete.
--time <number>
Section titled “--time <number>”Time budget in milliseconds per benchmark task.
modestbench --time 10000--limit-by <mode>
Section titled “--limit-by <mode>”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
# Explicit controlmodestbench --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 allSmart Defaults:
- Only
--iterations→ Usesiterationsmode (fast) - Only
--time→ Usestimemode - Both specified → Uses
anymode (whichever comes first) - Neither specified → Uses default iterations (100) with
iterationsmode
--warmup <number>
Section titled “--warmup <number>”Number of warmup iterations before measurement begins.
modestbench --warmup 100Helps stabilize JIT compilation for more consistent results.
--engine <name>
Section titled “--engine <name>”Select the benchmark engine. Options: tinybench (default) or accurate.
# Use the accurate engine for high-precision measurementsnode --allow-natives-syntax ./node_modules/.bin/modestbench --engine accurate
# Use tinybench engine (default)modestbench --engine tinybenchEngine 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-syntaxflag. Recommended for production benchmarks and critical performance measurements.
See the Getting Started guide for detailed comparison.
--timeout <number>
Section titled “--timeout <number>”Maximum time in milliseconds for a single task before timing out.
modestbench --timeout 60000Default: 30000 (30 seconds)
--bail
Section titled “--bail”Stop execution on first benchmark failure.
modestbench --bailUseful in CI/CD to fail fast when performance regressions are detected.
--reporter <name>, -r <name>
Section titled “--reporter <name>, -r <name>”Reporter to use for output. Can be specified multiple times.
# Single reportermodestbench --reporter json
# Multiple reporters simultaneouslymodestbench --reporter human --reporter json --reporter csv
# Using short aliasmodestbench -r human -r json -r csvAvailable reporters:
human- Color-coded terminal output (default for TTY with colors)simple- Plain text output (default for non-TTY environments)json- Structured JSON datacsv- Tabular CSV format
--output <directory>
Section titled “--output <directory>”Directory path for saving benchmark results and reports.
modestbench --reporter json --reporter csv --output ./resultsWhen specified:
- JSON reporter writes to
{output}/results.json - CSV reporter writes to
{output}/results.csv - Human reporter still writes to stdout/stderr
--quiet
Section titled “--quiet”Minimal output mode. Suppresses progress bars and non-essential messages.
modestbench --quiet--verbose
Section titled “--verbose”Detailed output mode with additional debugging information.
modestbench --verbose--tag <name>, -t <name>
Section titled “--tag <name>, -t <name>”Run only benchmarks with specific tags (OR logic - matches ANY). Can be specified multiple times.
# Single tagmodestbench --tag fast
# Multiple tags (matches ANY)modestbench --tag string --tag array --tag algorithm
# Using short aliasmodestbench -t string -t arrayTags cascade from file → suite → task levels. If a benchmark has ANY of the specified tags, it will run.
--exclude-tag <name>, -e <name>
Section titled “--exclude-tag <name>, -e <name>”Exclude benchmarks with specific tags. Can be specified multiple times.
# Exclude one typemodestbench --exclude-tag slow
# Exclude multiple typesmodestbench --exclude-tag experimental --exclude-tag unstable
# Using short aliasmodestbench -e experimental -e unstable--concurrent
Section titled “--concurrent”Run benchmark files concurrently (experimental).
modestbench --concurrentComplete Example
Section titled “Complete Example”modestbench \ --config ./config.json \ --iterations 2000 \ --warmup 50 \ -r human \ -r json \ -r csv \ --output ./results \ -t performance \ -t algorithm \ -e experimental \ --quiet \ benchmarks/modestbench init
Section titled “modestbench init”Initialize a project with configuration and example benchmarks.
# Interactive initializationmodestbench init
# Specify project typemodestbench init basicmodestbench init advancedmodestbench init library
# Specify config formatmodestbench init --config-type typescriptmodestbench init --config-type jsonmodestbench init --config-type yamlmodestbench init --config-type jsProject Types
Section titled “Project Types”-
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
What It Does
Section titled “What It Does”- Generates a configuration file in your chosen format
- Creates an example benchmark file
- Appends
.modestbench/to.gitignoreto exclude historical data
modestbench analyze (alias: profile)
Section titled “modestbench analyze (alias: profile)”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).
Analysis Basics
Section titled “Analysis Basics”# Analyze a commandmodestbench analyze "npm test"
# Analyze a scriptmodestbench analyze "node ./src/server.js"
# Analyze existing profilemodestbench analyze --input isolate-0x123-v8.logProfiling Options
Section titled “Profiling Options”[command]
Section titled “[command]”The command to analyze (e.g., "npm test", "node script.js").
modestbench analyze "npm test"--input, -i <path>
Section titled “--input, -i <path>”Path to an existing V8 CPU profile file (*.cpuprofile).
modestbench analyze --input CPU.20231027.161625.89167.0.001.cpuprofile--filter-file <pattern>
Section titled “--filter-file <pattern>”Filter functions by file glob pattern. Useful for focusing on specific modules.
# Only show functions in utilsmodestbench analyze "npm test" --filter-file "**/utils/**"
# Focus on specific filesmodestbench analyze "npm test" --filter-file "**/src/core/**"--min-percent <number>
Section titled “--min-percent <number>”Minimum execution percentage to display (default: 0.5).
# Only show functions using ≥5% execution timemodestbench analyze "npm test" --min-percent 5.0--top, -n <number>
Section titled “--top, -n <number>”Number of top functions to show (default: 25).
# Show top 50 functionsmodestbench analyze "npm test" --top 50
# Show top 10 onlymodestbench analyze "npm test" -n 10--group-by-file
Section titled “--group-by-file”Group results by source file for a file-centric view.
modestbench analyze "npm test" --group-by-fileThis groups functions by their source file and shows:
- Total percentage for each file
- Individual functions within each file
- Line numbers for each function
--color
Section titled “--color”Enable or disable colored output (auto-detected by default).
# Force colorsmodestbench analyze "npm test" --color
# Disable colorsmodestbench analyze "npm test" --no-colorAnalysis Example
Section titled “Analysis Example”modestbench analyze "npm test" \ --filter-file "**/src/**" \ --min-percent 2.0 \ --top 50 \ --group-by-fileOutput Format
Section titled “Output Format”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
modestbench test
Section titled “modestbench test”Run existing test files as benchmarks. Captures test definitions from Jest, Mocha, node:test, or AVA test files and executes them as benchmark tasks.
# Run Jest tests as benchmarksmodestbench test jest "test/*.test.js"
# Run Mocha tests as benchmarksmodestbench test mocha "test/*.spec.js"
# Run node:test files as benchmarksmodestbench test node-test "test/*.test.js"
# Run AVA tests as benchmarksmodestbench test ava "test/*.js"
# Multiple patternsmodestbench test mocha "test/unit/*.spec.js" "test/integration/*.spec.js"Supported Frameworks
Section titled “Supported Frameworks”jest- Jest test files usingdescribe/it/testsyntaxmocha- Mocha test files usingdescribe/itsyntaxnode-test- Node.js built-in test runner (node:testmodule)ava- AVA test files
Test Command Options
Section titled “Test Command Options”<framework> (required)
Section titled “<framework> (required)”The test framework to use. Must be one of: jest, mocha, node-test, ava.
[files..]
Section titled “[files..]”Test file paths or glob patterns.
modestbench test mocha "test/**/*.spec.js"--iterations <number>, -i <number>
Section titled “--iterations <number>, -i <number>”Number of iterations per test (default: 100).
modestbench test mocha test/*.spec.js --iterations 500--warmup <number>, -w <number>
Section titled “--warmup <number>, -w <number>”Number of warmup iterations before measurement (default: 5).
modestbench test mocha test/*.spec.js --warmup 10--bail, -b
Section titled “--bail, -b”Stop on first failure.
modestbench test mocha test/*.spec.js --bail--json
Section titled “--json”Output results in JSON format.
modestbench test mocha test/*.spec.js --json--quiet, -q
Section titled “--quiet, -q”Minimal output mode.
modestbench test mocha test/*.spec.js --quietHow It Works
Section titled “How It Works”The test command:
- Captures test definitions by intercepting the test framework’s API
- Converts test suites to benchmark suites and tests to benchmark tasks
- Preserves setup/teardown hooks (
beforeEach/afterEach) - Executes each test multiple times to collect timing statistics
Test hierarchy is preserved: describe blocks become benchmark suites, it/test blocks become benchmark tasks.
Use Cases
Section titled “Use Cases”- 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
Test Command Examples
Section titled “Test Command Examples”# Basic Mocha benchmarkingmodestbench test mocha "test/*.spec.js"
# node:test with more iterationsmodestbench test node-test "test/*.test.js" --iterations 500
# AVA with JSON output for CImodestbench test ava "test/*.js" --json --quiet
# Stop on first slow testmodestbench test mocha "test/unit/*.spec.js" --bailmodestbench history
Section titled “modestbench history”Manage benchmark history and compare results over time.
history list
Section titled “history list”List recent benchmark runs.
modestbench history listhistory show <run-id>
Section titled “history show <run-id>”Show detailed results for a specific run.
modestbench history show run-2025-10-07-001history compare <run-id-1> <run-id-2>
Section titled “history compare <run-id-1> <run-id-2>”Compare two benchmark runs.
modestbench history compare run-2025-10-07-001 run-2025-10-07-002history export
Section titled “history export”Export historical data.
# Export to CSVmodestbench history export --format csv --output results.csv
# Export to JSONmodestbench history export --format json --output results.jsonhistory clean
Section titled “history clean”Clean old benchmark data.
# Clean runs older than 30 daysmodestbench history clean --older-than 30d
# Keep only last 10 runsmodestbench history clean --keep 10
# Clean by sizemodestbench history clean --max-size 100mbGlobal Options
Section titled “Global Options”These options work with all commands:
--help
Section titled “--help”Show help information.
modestbench --helpmodestbench --help # shows run command help (default command)modestbench history --help--version
Section titled “--version”Show version number.
modestbench --versionEnvironment Variables
Section titled “Environment Variables”modestbench respects several environment variables:
Enable debug mode with detailed logging.
DEBUG=1 modestbenchShows full error stack traces and additional debugging information.
Automatically detected CI environment flag.
CI=true modestbenchWhen detected:
- Captures CI provider information
- Stores build details in results
- May adjust defaults for CI-friendly output
NODE_ENV
Section titled “NODE_ENV”Node.js environment mode. Stored in benchmark results for context.
NODE_ENV=production modestbenchFORCE_COLOR / NO_COLOR
Section titled “FORCE_COLOR / NO_COLOR”Control color output in terminal.
# Force color outputFORCE_COLOR=1 modestbench
# Disable color outputNO_COLOR=1 modestbenchConfiguration Priority
Section titled “Configuration Priority”Command-line flags override configuration file settings:
{ "iterations": 1000, "reporters": ["human"]}# CLI flags take precedencemodestbench --iterations 5000 --reporter json# Result: iterations=5000, reporters=["json"]Priority order:
- Default values (lowest)
- Configuration file
- CLI flags (highest)
Examples
Section titled “Examples”Quick Development Testing
Section titled “Quick Development Testing”modestbench --iterations 10 --quietProduction Benchmarking
Section titled “Production Benchmarking”modestbench \ --iterations 5000 \ --warmup 100 \ -r human \ -r json \ -r csv \ --output ./resultsCI/CD Integration
Section titled “CI/CD Integration”modestbench \ -r json \ -r csv \ --output ./benchmark-results \ --quiet \ --bail \ -t criticalRegression Testing
Section titled “Regression Testing”# Run current benchmarksmodestbench --reporter json --output ./current
# Compare with baselinemodestbench history compare baseline-run-id $(modestbench history list --format json | jq -r '.[0].id')Next Steps
Section titled “Next Steps”- Learn about Configuration file options
- Understand Output Formats for reporter details
- Explore Advanced Usage for complex scenarios