Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { defineConfig } from 'eslint/config';
import globals from 'globals';
import tseslint from 'typescript-eslint';

import numericSeparatorsPlugin from './vendor/eslint-numeric-separators-style/index.js';

// TODO: setup eslint-plugin-n
export default defineConfig(
jsPlugin.configs.recommended,
Expand All @@ -25,6 +27,7 @@ export default defineConfig(
plugins: {
'@perfectionist': perfectionist,
'@stylistic': stylistic,
'numeric-separators': numericSeparatorsPlugin,
},
rules: {
'@perfectionist/sort-classes': ['error', { partitionByNewLine: true }],
Expand All @@ -42,7 +45,6 @@ export default defineConfig(
],
'@stylistic/lines-between-class-members': ['error', 'always'],
'@stylistic/semi': 'error',

'@typescript-eslint/consistent-type-exports': [
'error',
{ fixMixedExportsWithInlineTypeSpecifier: true },
Expand Down Expand Up @@ -92,9 +94,9 @@ export default defineConfig(

// these 6 bytes add up
'@typescript-eslint/require-await': 'off',

// I like my template expressions, tyvm
'@typescript-eslint/restrict-template-expressions': 'off',

'@typescript-eslint/unified-signatures': [
'error',
{
Expand All @@ -111,6 +113,7 @@ export default defineConfig(
'no-constructor-return': 'error',

'no-empty': ['error', { allowEmptyCatch: true }],

'no-restricted-syntax': [
'error',
{
Expand All @@ -121,6 +124,7 @@ export default defineConfig(
},
],
'no-self-compare': 'error',
'numeric-separators/numeric-separators-style': 'error',
'object-shorthand': ['error', 'always'],
'prefer-arrow-callback': 'error',
semi: 'error',
Expand Down
6 changes: 3 additions & 3 deletions examples/bench/performance-tips.bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default {
benchmarks: {
// Fast operations need more iterations
'Array Access': {
config: { iterations: 10000 },
config: { iterations: 10_000 },
fn: () => iterationState.smallArray[50],
tags: ['fast', 'array'],
},
Expand All @@ -46,7 +46,7 @@ export default {
iterationState.smallArray = Array.from({ length: 100 }, (_, i) => i);
iterationState.largeComputation = () => {
let result = 0;
for (let i = 0; i < 100000; i++) {
for (let i = 0; i < 100_000; i++) {
result += Math.sqrt(i);
}
return result;
Expand Down Expand Up @@ -84,7 +84,7 @@ export default {

setup: () => {
// Generate large dataset once for all benchmarks
optimizationState.dataset = Array.from({ length: 10000 }, (_, i) => ({
optimizationState.dataset = Array.from({ length: 10_000 }, (_, i) => ({
id: i,
name: `item-${i}`,
value: Math.random(),
Expand Down
14 changes: 7 additions & 7 deletions examples/profiling-demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

// Medium function - string manipulation
const parseAndFormat = () => {
const data = Array.from({ length: 100000 }, (_, i) => {
const data = Array.from({ length: 100_000 }, (_, i) => {
const raw = `${i}|item-${i}|${Math.random() * 100}`;
const parts = raw.split('|');
return {
Expand All @@ -23,7 +23,7 @@ const parseAndFormat = () => {

// Warm function - moderate CPU time
const processStrings = () => {
const strings = Array.from({ length: 500000 }, (_, i) => `item-${i}`);
const strings = Array.from({ length: 500_000 }, (_, i) => `item-${i}`);
return strings
.map((s) => s.toUpperCase())
.filter((s) => s.includes('5'))
Expand All @@ -32,7 +32,7 @@ const processStrings = () => {

// Medium-warm function - JSON serialization
const serializeData = () => {
const data = Array.from({ length: 50000 }, (_, i) => ({
const data = Array.from({ length: 50_000 }, (_, i) => ({
id: i,
metadata: { created: Date.now(), updated: Date.now() },
name: `Record ${i}`,
Expand All @@ -48,13 +48,13 @@ const simpleCalculation = () => {

// Hot function - lots of CPU time
const sortLargeArray = () => {
const arr = Array.from({ length: 1000000 }, () => Math.random());
const arr = Array.from({ length: 1_000_000 }, () => Math.random());
return arr.sort((a, b) => a - b);
};

// Warm function - object manipulation
const transformData = () => {
const data = Array.from({ length: 200000 }, (_, i) => ({
const data = Array.from({ length: 200_000 }, (_, i) => ({
id: i,
name: `Item ${i}`,
value: Math.random() * 100,
Expand All @@ -72,7 +72,7 @@ const transformData = () => {
// Another hot function - regex processing
const validateEmails = () => {
const emails = Array.from(
{ length: 100000 },
{ length: 100_000 },
(_, i) => `user${i}@example.com`,
);
const regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
Expand Down Expand Up @@ -111,7 +111,7 @@ validateEmails();
transformData();

console.log('Simple calculations (cold path)...');
for (let i = 0; i < 10000; i++) {
for (let i = 0; i < 10_000; i++) {
simpleCalculation();
}

Expand Down
16 changes: 8 additions & 8 deletions src/cli/commands/baseline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ const formatDuration = (nanoseconds: number): string => {
if (nanoseconds < 1000) {
return `${nanoseconds.toFixed(2)}ns`;
}
if (nanoseconds < 1000000) {
if (nanoseconds < 1_000_000) {
return `${(nanoseconds / 1000).toFixed(2)}μs`;
}
if (nanoseconds < 1000000000) {
return `${(nanoseconds / 1000000).toFixed(2)}ms`;
if (nanoseconds < 1_000_000_000) {
return `${(nanoseconds / 1_000_000).toFixed(2)}ms`;
}
return `${(nanoseconds / 1000000000).toFixed(2)}s`;
return `${(nanoseconds / 1_000_000_000).toFixed(2)}s`;
};

/**
Expand All @@ -85,13 +85,13 @@ const formatOpsPerSec = (ops: number): string => {
if (ops < 1000) {
return `${ops.toFixed(2)} ops/sec`;
}
if (ops < 1000000) {
if (ops < 1_000_000) {
return `${(ops / 1000).toFixed(2)}K ops/sec`;
}
if (ops < 1000000000) {
return `${(ops / 1000000).toFixed(2)}M ops/sec`;
if (ops < 1_000_000_000) {
return `${(ops / 1_000_000).toFixed(2)}M ops/sec`;
}
return `${(ops / 1000000000).toFixed(2)}B ops/sec`;
return `${(ops / 1_000_000_000).toFixed(2)}B ops/sec`;
};

/**
Expand Down
4 changes: 2 additions & 2 deletions src/cli/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const PROJECT_TEMPLATES = {
outputDir: DEFAULT_OUTPUT_DIR,
pattern: `${DEFAULT_BENCHMARK_DIR}/**/*.bench.{js,ts}`,
reporters: ['human', 'json'],
time: 10000,
time: 10_000,
warmup: 50,
},
description: 'Feature-rich setup with multiple reporters and configuration',
Expand All @@ -77,7 +77,7 @@ const PROJECT_TEMPLATES = {
outputDir: DEFAULT_OUTPUT_DIR,
pattern: `${DEFAULT_BENCHMARK_DIR}/**/*.bench.{js,ts}`,
reporters: ['human', 'json'],
time: 15000,
time: 15_000,
warmup: 100,
},
description: 'Optimized for library performance testing',
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const getDefaultTestConfig = (
tags: [],
thresholds: {},
time: 1000,
timeout: 30000,
timeout: 30_000,
verbose,
warmup,
});
Expand Down
2 changes: 1 addition & 1 deletion src/config/budget-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const parseTimeString = (value: string): number => {
ms: 1_000_000,
ns: 1,
s: 1_000_000_000,
us: 1_000,
us: 1000,
};

return num * multipliers[unit as keyof typeof multipliers];
Expand Down
2 changes: 1 addition & 1 deletion src/core/engines/accurate-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class AccurateEngine extends ModestBenchEngine {
* Maximum iterations per round to prevent overwhelming Node.js test runner
* and excessive memory usage
*/
private static readonly MAX_ITERATIONS_PER_ROUND = 10000;
private static readonly MAX_ITERATIONS_PER_ROUND = 10_000;

/**
* Maximum iterations per round for async functions (much lower due to
Expand Down
12 changes: 6 additions & 6 deletions src/formatters/history/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ export class HistoryCompareFormatter implements HistoryFormatter<CompareResult>
lines.push('');

for (const comparison of data.tasksInBoth) {
const mean1 = comparison.run1!.mean / 1000000; // Convert to ms
const mean2 = comparison.run2!.mean / 1000000;
const mean1 = comparison.run1!.mean / 1_000_000; // Convert to ms
const mean2 = comparison.run2!.mean / 1_000_000;
const changeSign = comparison.percentChange >= 0 ? '+' : '';
const changeStr = `${changeSign}${comparison.percentChange.toFixed(1)}%`;

Expand All @@ -73,8 +73,8 @@ export class HistoryCompareFormatter implements HistoryFormatter<CompareResult>
);

// Min - highlight higher number
const min1 = comparison.run1!.min / 1000000;
const min2 = comparison.run2!.min / 1000000;
const min1 = comparison.run1!.min / 1_000_000;
const min2 = comparison.run2!.min / 1_000_000;
const minHigher = min2 > min1;
const min1Str = minHigher
? colorize('magenta', `${min1.toFixed(3)}ms`)
Expand All @@ -87,8 +87,8 @@ export class HistoryCompareFormatter implements HistoryFormatter<CompareResult>
);

// Max - highlight higher number
const max1 = comparison.run1!.max / 1000000;
const max2 = comparison.run2!.max / 1000000;
const max1 = comparison.run1!.max / 1_000_000;
const max2 = comparison.run2!.max / 1_000_000;
const maxHigher = max2 > max1;
const max1Str = maxHigher
? colorize('magenta', `${max1.toFixed(3)}ms`)
Expand Down
4 changes: 2 additions & 2 deletions src/formatters/history/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ const formatTime = (ns: number): string => {
if (ns < 1000) {
return `${ns.toFixed(2)}ns`;
}
if (ns < 1000000) {
if (ns < 1_000_000) {
return `${(ns / 1000).toFixed(3)}µs`;
}
return `${(ns / 1000000).toFixed(3)}ms`;
return `${(ns / 1_000_000).toFixed(3)}ms`;
};
2 changes: 1 addition & 1 deletion src/formatters/history/trends.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const NS_PER_MS = 1_000_000;
/**
* Nanoseconds per microsecond conversion constant
*/
const NS_PER_US = 1_000;
const NS_PER_US = 1000;

/**
* Intelligently format a time range with appropriate precision Displays
Expand Down
8 changes: 5 additions & 3 deletions src/reporters/human.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export class HumanReporter extends BaseReporter {
);
}
this.printLine(
`${this.colorize('cyan', ansiChars.approx + ' Duration:')} ${this.colorize('brightWhite', BaseReporter.formatDuration(duration * 1000000))}`,
`${this.colorize('cyan', ansiChars.approx + ' Duration:')} ${this.colorize('brightWhite', BaseReporter.formatDuration(duration * 1_000_000))}`,
);
this.printLine();

Expand Down Expand Up @@ -463,7 +463,7 @@ export class HumanReporter extends BaseReporter {
});

const durationStr = BaseReporter.formatDuration(
result.duration * 1000000,
result.duration * 1_000_000,
);

// Display suite setup failure
Expand All @@ -487,7 +487,9 @@ export class HumanReporter extends BaseReporter {
const passed = result.tasks.filter((t) => !t.error && !t.aborted).length;
const failed = result.tasks.filter((t) => t.error).length;
const aborted = result.tasks.filter((t) => t.aborted).length;
const durationStr = BaseReporter.formatDuration(result.duration * 1000000); // ms to ns
const durationStr = BaseReporter.formatDuration(
result.duration * 1_000_000,
); // ms to ns

// Build summary parts
const parts: string[] = [];
Expand Down
2 changes: 1 addition & 1 deletion src/reporters/nyan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ export class NyanReporter extends BaseReporter {
*/
private printEpilogue(run: BenchmarkRun): void {
const duration = Date.now() - this.startTime;
const durationStr = BaseReporter.formatDuration(duration * 1000000);
const durationStr = BaseReporter.formatDuration(duration * 1_000_000);

console.log();
console.log(
Expand Down
4 changes: 2 additions & 2 deletions src/services/budget-evaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ export class BudgetEvaluator {
* Format time in nanoseconds to human-readable string
*/
private static formatTime(this: void, nanoseconds: number): string {
if (nanoseconds < 1_000) {
if (nanoseconds < 1000) {
return `${nanoseconds.toFixed(0)}ns`;
} else if (nanoseconds < 1_000_000) {
return `${(nanoseconds / 1_000).toFixed(2)}μs`;
return `${(nanoseconds / 1000).toFixed(2)}μs`;
} else if (nanoseconds < 1_000_000_000) {
return `${(nanoseconds / 1_000_000).toFixed(2)}ms`;
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/services/config-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const DEFAULT_CONFIG: ModestBenchConfig = {
tags: [],
thresholds: {},
time: 1000, // 1 second minimum for tinybench to gather samples
timeout: 30000, // 30 seconds
timeout: 30_000, // 30 seconds
verbose: false, // No verbose output by default
warmup: 30, // Light warmup by default - enough for basic JIT optimization
};
Expand Down Expand Up @@ -291,7 +291,7 @@ export class ModestBenchConfigurationManager implements ConfigurationManager {
}

// Warn about potentially long runtime
if (validConfig.iterations > 1000 && validConfig.time > 60000) {
if (validConfig.iterations > 1000 && validConfig.time > 60_000) {
warnings.push({
code: 'LONG_RUNTIME_WARNING',
file: 'configuration',
Expand Down
16 changes: 8 additions & 8 deletions src/services/reporter-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ export abstract class BaseReporter implements Reporter {
protected static formatDuration(this: void, nanoseconds: number): string {
if (nanoseconds < 1000) {
return `${nanoseconds.toFixed(2)}ns`;
} else if (nanoseconds < 1000000) {
} else if (nanoseconds < 1_000_000) {
return `${(nanoseconds / 1000).toFixed(2)}μs`;
} else if (nanoseconds < 1000000000) {
return `${(nanoseconds / 1000000).toFixed(2)}ms`;
} else if (nanoseconds < 1_000_000_000) {
return `${(nanoseconds / 1_000_000).toFixed(2)}ms`;
} else {
return `${(nanoseconds / 1000000000).toFixed(2)}s`;
return `${(nanoseconds / 1_000_000_000).toFixed(2)}s`;
}
}

Expand All @@ -57,12 +57,12 @@ export abstract class BaseReporter implements Reporter {
): string {
if (opsPerSecond < 1000) {
return `${opsPerSecond.toFixed(2)} ops/sec`;
} else if (opsPerSecond < 1000000) {
} else if (opsPerSecond < 1_000_000) {
return `${(opsPerSecond / 1000).toFixed(2)}K ops/sec`;
} else if (opsPerSecond < 1000000000) {
return `${(opsPerSecond / 1000000).toFixed(2)}M ops/sec`;
} else if (opsPerSecond < 1_000_000_000) {
return `${(opsPerSecond / 1_000_000).toFixed(2)}M ops/sec`;
} else {
return `${(opsPerSecond / 1000000000).toFixed(2)}B ops/sec`;
return `${(opsPerSecond / 1_000_000_000).toFixed(2)}B ops/sec`;
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/config/test-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default {
maxMean: 1000,
},
time: 2000,
timeout: 60000,
timeout: 60_000,
verbose: true,
warmup: 100,
};
2 changes: 1 addition & 1 deletion test/fixtures/config/test-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const config: Partial<ModestBenchConfig> = {
maxMean: 1000,
},
time: 2000,
timeout: 60000,
timeout: 60_000,
verbose: true,

warmup: 100,
Expand Down
Loading