Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
benchmarkify
Advanced tools
Benchmark framework for NodeJS for measure the execution time of JS codes.
$ npm install benchmarkify --save-dev
Example benchmark suite
const Benchmarkify = require("benchmarkify");
// Create a new benchmark
// The `.printHeader` method will print the name of benchmark & some
// information from the OS/PC to the console.
const benchmark = new Benchmarkify("Simple example").printHeader();
let i = 0;
// Create a test suite
const bench1 = benchmark.createSuite("Increment integer");
// Add first func
bench1.add("Increment with ++", () => {
i++;
});
// Add second func. This result will be the reference
bench1.ref("Increment with i + 1", () => {
i = i + 1;
});
bench1.run();
Output
==================
Simple example
==================
Platform info:
==============
Windows_NT 6.1.7601 x64
Node.JS: 6.10.0
V8: 5.1.281.93
Intel(R) Core(TM) i7-4770K CPU @ 3.50GHz × 8
Suite: Increment integer
√ Increment with ++ 98,878,885 rps
√ Increment with i + 1 89,930,539 rps
Increment with ++ +9.95% (98,878,885 rps) (avg: 10ns)
Increment with i + 1 (#) 0% (89,930,539 rps) (avg: 11ns)
-----------------------------------------------------------------------
JSON result
If you need the results in JSON use .then
after run()
bench1.run().then(res => console.log(res));
Result on console:
[
{
name: 'Increment with ++',
fastest: true,
stat: {
duration: 4.999651845,
cycle: 492086,
count: 492086000,
avg: 1.0160118038310376e-8,
rps: 98424053.36525989,
percent: 9.95071720945748
}
},
{
name: 'Increment with i + 1',
reference: true,
stat: {
duration: 4.999535403,
cycle: 447541,
count: 447541000,
avg: 1.117112265244972e-8,
rps: 89516517.82112603,
percent: 0
}
}
]
const benchmark = new Benchmarkify("Benchmark #1", opts);
logger
- print messages to this logger. Default: console
spinner
- show spinner when running tests. Default: true
minSamples
- Minimum samples. Default: 0
- not useddescription
- Custom description field.meta
- To store any meta information. Result JSON contains it.createSuite
- Create a new benchmark suite.run(suites: Array): Promise
-const bench1 = benchmark.createSuite("Date performance", { time: 1000 });
name
- Name of suite.time
- Time of test. Default: 5000
(5sec)minSamples
- Minimum samples. Default 0
- disableddescription
- Custom description field.meta
- To store any meta information. Result JSON contains it.add(name: string, fn: Function, opts: Object)
- Add a function to the suiteskip(name: string, fn: Function, opts: Object)
- Skip the functiononly(name: string, fn: Function, opts: Object)
- Run only this functionref(name: string, fn: Function, opts: Object)
- Add a function and it'll be the referencerun(): Promise
- Run the suite.setup(fn): Promise
- Function to execute before test suite.tearDown(fn): Promise
- Function to execute after test suite.If you would like to test async function use the done
callback.
bench.add("Async call test", done => {
asyncFunction(data).then(() => done());
});
or
bench.add("Async call test", async done => {
await asyncFunction(data)
done();
});
Benchmarkify is available under the MIT license.
Copyright (C) 2021 Icebob
FAQs
Benchmark runner for NodeJS
The npm package benchmarkify receives a total of 1,500 weekly downloads. As such, benchmarkify popularity was classified as popular.
We found that benchmarkify 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.