1.0.4 • Published 3 months ago
@digigov/benchmark v1.0.4
@digigov/benchmark
@digigov/benchmark
is a lightweight utility to assist with the profiling of JavaScript code, offering insights into
execution time and memory usage during benchmark runs. Performance is measured by running the code for a specified
amount of iterations, and calculating the average operations per millisecond and memory usage per millisecond.
Features
- Simple and configurable benchmark setup
- Customizable iteration and concurrency settings for benchmarks
- Support for async benchmarks
- Detailed profiling report, with execution time (in milliseconds) and memory usage metrics
Installation
npm install @digigov/benchmark
Usage
- Initialization
import BenchmarkProfiler from '@digigov/benchmark';
const profiler = new BenchmarkProfiler({
iterations: 1000, // optional
concurrency: 1, // optional
});
- Adding benchmarks
profiler.add({
name: 'Name of the benchmark',
fn: async () => {
// Benchmark code
},
beforeAll: async () => {
// Optional. Runs once before all iterations
},
afterAll: async () => {
// Optional. Runs once after all iterations
},
beforeEach: async () => {
// Optional. Runs before each iteration
},
afterEach: async () => {
// Optional. Runs after each iteration
},
});
- Running benchmarks
const results = await profiler.run();
console.log(results);
Result Structure
Results from the run()
function return an array with each benchmark's result:
[
{
name: string, // Name of the benchmark
iterations: number, // Number of iterations run
timeInMs: number, // Total time taken for all iterations in milliseconds
averageOpsPerMs: number, // Average operations per millisecond
averageKbPerMs: number, // Average memory used per millisecond
maxKb: number, // Peak memory usage during the benchmark run
},
];
1.0.4
3 months ago
1.0.4-fd2cea11
3 months ago
1.0.2
3 months ago
1.1.0
3 months ago
1.0.3
3 months ago
1.1.0-2a507fd6
5 months ago
1.0.1
5 months ago
1.0.0
5 months ago
1.0.0-rc.5
5 months ago
1.0.0-rc.6
5 months ago
1.0.0-23c81d9f
5 months ago
1.0.0-51c931ab
5 months ago
0.1.0-47312a12
5 months ago
0.1.0-b0737a96
5 months ago
0.1.0-rc.4
5 months ago
0.1.0-8b33e4c8
5 months ago
0.1.0-b4257f67
5 months ago
0.1.0-a131264d
5 months ago
0.1.0-ab30975f
5 months ago
0.1.0-e322b0cc
6 months ago
0.1.0-05af31dd
6 months ago
0.1.0-00643e1d
6 months ago
0.1.0-eb2842b4
6 months ago
0.1.0-rc.3
6 months ago
0.1.0-8bbf3ef2
6 months ago
0.1.0-rc.2
6 months ago
0.1.0-rc.1
6 months ago