
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
A modern benchmarking library for Node.js, capable of generating statistically significant results.
npm install --save-dev nodemark
const benchmark = require('nodemark');
const result = benchmark(myFunction, setupFunction);
console.log(result); // => 14,114,886 ops/sec ±0.58% (7906233 samples)
console.log(result.nanoseconds()); // => 71
In benchmarking, it's important to generate statistically significant results. Thankfully, nodemark
makes this easy:
nodemark
is factored out of the results.The combination of these things makes it a highly accurate measuring device. However, any benchmark done in JavaScript has its limits. If the average time measured by a benchmark is too small to be reliable (< 10ns), the results will be NaN
in order to avoid providing misleading information.
Runs a new benchmark. This measures the performance of the subject
function. If a setup
function is provided, it will be invoked before every execution of subject
.
By default, the benchmark runs for about 3 seconds, but this can be overridden by passing a duration
number (in milliseconds). Regardless of the desired duration, the benchmark will not finish until the subject
has been run at least 10 times.
Both subject
and setup
can run asynchronously by declaring a callback argument in their signature. If you do this, you must invoke the callback to indicate that the operation is complete. When running an asyncronous benchmark, this function returns a promise. However, because subject
and setup
use callbacks rather than promises, synchronous errors will not automatically be caught.
benchmark(callback => fs.readFile('foo.txt', callback))
.then(console.log);
There is no plan to support promises in
subject
andsetup
because it would cause too much overhead and yield inaccurate results.
Each benchmark returns an immutable object describing the result of that benchmark. It has five properties:
mean
, the average measured time in nanosecondserror
, the margin of error as a ratio of the meanmax
, the fastest measured time in nanosecondsmin
, the slowest measured time in nanosecondscount
, the number of times the subject was invoked and measuredReturns this.mean
, rounded to the nearest whole number or the number or decimal places specified by precision
.
Same as .nanoseconds(), but the value is in microseconds.
Same as .nanoseconds(), but the value is in milliseconds.
Same as .nanoseconds(), but the value is in seconds.
Returns the average number of executions per second, rounded to the nearest whole number or the number of decimal places specified by precision
.
Returns the standard deviation in nanoseconds, rounded to the nearest whole number or the number of decimal places specified by precision
.
Returns a nicely formatted string describing the result of the benchmark. By default, the "hz"
format is used, which displays ops/sec, but you can optionally specify "nanoseconds"
, "microseconds"
, "milliseconds"
, or "seconds"
to change the displayed information.
FAQs
A modern benchmarking library for Node.js
The npm package nodemark receives a total of 1,061 weekly downloads. As such, nodemark popularity was classified as popular.
We found that nodemark 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.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.