Skip to content

Configuration

modestbench supports multiple configuration file formats, powered by cosmiconfig:

  • JSON: modestbench.config.json, .modestbenchrc.json, .modestbenchrc
  • YAML: modestbench.config.yaml, modestbench.config.yml, .modestbenchrc.yaml, .modestbenchrc.yml
  • JavaScript: modestbench.config.js, modestbench.config.mjs, .modestbenchrc.js, .modestbenchrc.mjs
  • TypeScript: modestbench.config.ts
  • package.json: Use a "modestbench" field

modestbench automatically searches for configuration files in the current directory and parent directories, following standard conventions.

Use the init command to generate a configuration file:

Terminal window
modestbench init --config-type json # JSON format
modestbench init --config-type yaml # YAML format
modestbench init --config-type js # JavaScript format
modestbench init --config-type ts # TypeScript format
{
"bail": false,
"exclude": ["node_modules/**"],
"excludeTags": ["slow", "experimental"],
"iterations": 1000,
"limitBy": "iterations",
"outputDir": "./benchmark-results",
"pattern": "benchmarks/**/*.bench.{js,ts}",
"quiet": false,
"reporters": ["human", "json"],
"tags": ["fast", "critical"],
"time": 5000,
"timeout": 30000,
"verbose": false,
"warmup": 50
}

Type: string | string[]
Default: ["**/*.bench.{js,ts,mjs,cjs,mts,cts}"]

Glob pattern(s) to discover benchmark files. Can be a single string or array of patterns.

{
"pattern": "benchmarks/**/*.bench.js"
}
{
"pattern": [
"benchmarks/**/*.bench.js",
"tests/perf/**/*.bench.ts"
]
}

Type: string[]
Default: ["node_modules/**"]

Glob patterns for files/directories to exclude from discovery.

{
"exclude": [
"node_modules/**",
"build/**",
"**/*.slow.bench.js"
]
}

Type: number
Default: 100

Number of samples to collect per benchmark task. Higher values provide more accurate results but take longer.

{
"iterations": 1000
}

Type: number (milliseconds)
Default: 1000

Time budget in milliseconds per benchmark task. Works with limitBy to control benchmark duration.

{
"time": 5000
}

Type: "iterations" | "time" | "any" | "all"
Default: Smart default based on which options are provided

Controls how benchmarks are limited:

  • iterations: Stop after N samples (time budget set to 1ms)
  • time: Run for T milliseconds (collect as many samples as possible)
  • any: Stop when either threshold is reached (defaults to iterations behavior)
  • all: Require both time AND iterations thresholds (tinybench default)
{
"limitBy": "time"
}

Smart Defaults:

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

Type: number
Default: 0

Number of warmup iterations before measurement begins. Helps stabilize JIT compilation.

{
"warmup": 50
}

Type: number (milliseconds)
Default: 30000

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

{
"timeout": 60000
}

Type: boolean
Default: false

Stop execution on first benchmark failure.

{
"bail": true
}

Type: string[]
Default: Auto-selected based on environment

Array of reporter names to use for output. Available reporters:

  • human - Color-coded terminal output with progress bars (default for TTY with colors)
  • simple - Plain text output without colors (default for non-TTY environments)
  • json - Structured JSON data for programmatic analysis
  • csv - Tabular data for spreadsheets
{
"reporters": ["human", "json", "csv"]
}

Type: string
Default: undefined

Directory path for saving benchmark results and reports. When specified:

  • JSON reporter writes to {outputDir}/results.json
  • CSV reporter writes to {outputDir}/results.csv
  • Human reporter still writes to stdout/stderr
{
"outputDir": "./benchmark-results"
}

Type: boolean
Default: false

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

{
"quiet": true
}

Type: boolean
Default: false

Detailed output mode with additional debugging information.

{
"verbose": true
}

Type: string[]
Default: []

Array of tags to include. If non-empty, only benchmarks with ANY of these tags will run.

{
"tags": ["fast", "critical"]
}

Uses OR logic - benchmarks matching ANY tag will run.

Type: string[]
Default: []

Array of tags to exclude. Benchmarks with ANY of these tags will be skipped.

{
"excludeTags": ["slow", "experimental"]
}

Configuration is merged in the following order (later sources override earlier ones):

  1. Default values - Built-in defaults
  2. Configuration file - Project config file
  3. CLI flags - Command-line arguments

Example:

modestbench.config.json
{
"iterations": 1000,
"reporters": ["human", "json"]
}
Terminal window
# CLI flags override config file
modestbench --iterations 5000 --reporters csv
# Result: iterations=5000, reporters=["csv"]
{
"pattern": "benchmarks/**/*.bench.js",
"iterations": 1000,
"warmup": 50,
"reporters": ["human", "json"],
"outputDir": "./results"
}
pattern: benchmarks/**/*.bench.js
iterations: 1000
warmup: 50
reporters:
- human
- json
outputDir: ./results
modestbench.config.js
export default {
pattern: 'benchmarks/**/*.bench.js',
iterations: 1000,
warmup: 50,
reporters: ['human', 'json'],
outputDir: './results',
};
modestbench.config.ts
import type { ModestBenchConfig } from 'modestbench';
const config: ModestBenchConfig = {
pattern: 'benchmarks/**/*.bench.ts',
iterations: 1000,
warmup: 50,
reporters: ['human', 'json'],
outputDir: './results',
};
export default config;
{
"name": "my-package",
"version": "1.0.0",
"modestbench": {
"pattern": "benchmarks/**/*.bench.js",
"iterations": 1000,
"reporters": ["human", "json"]
}
}

You can use JavaScript/TypeScript config files for dynamic configuration:

modestbench.config.js
const isCI = process.env.CI === 'true';
export default {
iterations: isCI ? 5000 : 100,
warmup: isCI ? 100 : 0,
reporters: isCI ? ['json', 'csv'] : ['human'],
quiet: isCI,
outputDir: isCI ? './benchmark-results' : undefined,
};