npm install @ferrow/performance-profilerInstrumentation helpers over perf_hooks. Mark/measure, profile functions with memory delta, and hierarchical section timing with tree report.
import { PerformanceProfiler } from 'performance-profiler';
const profiler = new PerformanceProfiler();
// Section timing
profiler.start('main');
profiler.start('io');
// ... I/O work
profiler.end();
profiler.start('compute');
// ... CPU work
profiler.end();
profiler.end();
console.log(profiler.report());
// Performance Report
// ==================
// ├─ main 123.45ms (100.0%)
// ├─ io 50.23ms (40.7%)
// ├─ compute 73.22ms (59.3%)Create marks and measure duration between them.
profiler.mark('start');
// ... work
profiler.mark('end');
const ms = profiler.measure('task', 'start', 'end');Profile a function. Returns {result, durationMs, memoryDeltaBytes}.
const { result, durationMs, memoryDeltaBytes } = profiler.profile(() => heavyComputation());
const { result, durationMs, memoryDeltaBytes } = await profiler.profileAsync(async () => {
return await fetchData();
});Hierarchical section timing. Nesting creates tree structure.
profiler.start('parent');
profiler.start('child1');
// ... work
profiler.end();
profiler.start('child2');
// ... work
profiler.end();
profiler.end();Render tree with durations and percentages.
console.log(profiler.report());Clear all sections and marks.
- Hierarchical timing only — no flame graphs or detailed CPU analysis
- Memory delta via process.memoryUsage() — heap-only; GC may skew results
- perf_hooks.performance — browser-compatible interface
- In-process only — no cross-process tracing
- No overhead estimation — profiling has measurement overhead
MIT
Sponsored by Ferrow
Part of the ferrow-toolkit collection · Sponsored by Ferrow