Configuration
Configuration Files
Section titled “Configuration Files”modestbench supports multiple configuration file formats, powered by cosmiconfig:
Supported Formats
Section titled “Supported Formats”- 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
Configuration Discovery
Section titled “Configuration Discovery”modestbench automatically searches for configuration files in the current directory and parent directories, following standard conventions.
JSON Schema
Section titled “JSON Schema”A JSON Schema is published at https://modestbench.dev/modestbench-config.schema.json for IDE autocompletion and validation. Add the $schema property to your JSON config file:
{ "$schema": "https://modestbench.dev/modestbench-config.schema.json", "iterations": 1000, "reporters": ["human", "json"]}Generate a Configuration File
Section titled “Generate a Configuration File”Use the init command to generate a configuration file:
modestbench init --config-type json # JSON formatmodestbench init --config-type yaml # YAML formatmodestbench init --config-type js # JavaScript formatmodestbench init --config-type ts # TypeScript formatConfiguration Options Reference
Section titled “Configuration Options Reference”Complete Example
Section titled “Complete Example”{ "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}Option Details
Section titled “Option Details”pattern
Section titled “pattern”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" ]}exclude
Section titled “exclude”Type: string[]
Default: ["node_modules/**"]
Glob patterns for files/directories to exclude from discovery.
{ "exclude": [ "node_modules/**", "build/**", "**/*.slow.bench.js" ]}iterations
Section titled “iterations”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}limitBy
Section titled “limitBy”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
iterationsprovided →"iterations"mode (fast) - Only
timeprovided →"time"mode - Both provided →
"any"mode (whichever comes first) - Neither provided → Uses default iterations (100) with
"iterations"mode
warmup
Section titled “warmup”Type: number
Default: 0
Number of warmup iterations before measurement begins. Helps stabilize JIT compilation.
{ "warmup": 50}timeout
Section titled “timeout”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}reporters
Section titled “reporters”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 analysiscsv- Tabular data for spreadsheets
{ "reporters": ["human", "json", "csv"]}outputDir
Section titled “outputDir”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}verbose
Section titled “verbose”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.
excludeTags
Section titled “excludeTags”Type: string[]
Default: []
Array of tags to exclude. Benchmarks with ANY of these tags will be skipped.
{ "excludeTags": ["slow", "experimental"]}Configuration Priority
Section titled “Configuration Priority”Configuration is merged in the following order (later sources override earlier ones):
- Default values - Built-in defaults
- Configuration file - Project config file
- CLI flags - Command-line arguments
Example:
{ "iterations": 1000, "reporters": ["human", "json"]}# CLI flags override config filemodestbench --iterations 5000 --reporter csv# Result: iterations=5000, reporters=["csv"]Format-Specific Examples
Section titled “Format-Specific Examples”{ "pattern": "benchmarks/**/*.bench.js", "iterations": 1000, "warmup": 50, "reporters": ["human", "json"], "outputDir": "./results"}pattern: benchmarks/**/*.bench.jsiterations: 1000warmup: 50reporters: - human - jsonoutputDir: ./resultsJavaScript
Section titled “JavaScript”export default { pattern: 'benchmarks/**/*.bench.js', iterations: 1000, warmup: 50, reporters: ['human', 'json'], outputDir: './results',};TypeScript
Section titled “TypeScript”import type { ModestBenchConfig } from 'modestbench';
const config: ModestBenchConfig = { pattern: 'benchmarks/**/*.bench.ts', iterations: 1000, warmup: 50, reporters: ['human', 'json'], outputDir: './results',};
export default config;package.json
Section titled “package.json”{ "name": "my-package", "version": "1.0.0", "modestbench": { "pattern": "benchmarks/**/*.bench.js", "iterations": 1000, "reporters": ["human", "json"] }}Environment-Specific Configuration
Section titled “Environment-Specific Configuration”You can use JavaScript/TypeScript config files for dynamic configuration:
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,};Next Steps
Section titled “Next Steps”- See CLI Reference for command-line options
- Learn about Output Formats for reporter details
- Explore Advanced Usage for complex scenarios