Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
micro-bmark
Advanced tools
Benchmark your node.js projects with nanosecond resolution.
process.hrtime
for 1ns resolutionnpm install --save-dev micro-bmark
import * as bench from 'micro-bmark';
await bench.mark('printing', () => Promise.resolve(0));
const { mark, compare, run } = bench; // Or, use as such
run(async () => {
await mark('base', () => Promise.resolve(1));
await mark('sqrt', 10000, () => Math.sqrt(2));
await compare('math', 5000, {
lib1: () => Math.sqrt(2),
lib2: () => Math.sqrt(3)
});
// bench.utils.logMem(); // Log current RAM
// console.log(bench.utils.getTime(), bench.utils.formatD(bench.utils.getTime())); // Get current time in nanoseconds
});
Example output:
getPublicKey() x 6,072 ops/sec @ 164μs/op ± 8.22% (min: 143μs, max: 17ms)
sign x 4,980 ops/sec @ 200μs/op
signSync x 4,671 ops/sec @ 214μs/op
verify x 969 ops/sec @ 1ms/op
recoverPublicKey x 890 ops/sec @ 1ms/op
getSharedSecret aka ecdh x 585 ops/sec @ 1ms/op
await bench.run(args?, callback)
: Runs bunch of suites. Not requiredawait bench.mark(label?, samples?, callback)
: Measures callback (can be async) samples
timesawait bench.compare(label, samples, map)
: mark, but compares runs between object values
map
: { a: () => {}, b: () => {} }
bench.utils.logMem(): undefined
: Logs memory usagebench.utils.getTime(): bigint
: Returns current time in bigint.MIT License
Copyright (c) 2020 Paul Miller (https://paulmillr.com), (c) 2010-2016 Mathias Bynens, John-David Dalton, (c) Robert Kieffer from JSLitmus.js
FAQs
Benchmark your node.js projects with nanosecond resolution
We found that micro-bmark demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.