
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
benchmarkjs
Advanced tools
A easy benchmark framework for Javascript code.
Installing with npm:
$ npm install benchmarkjs --save-dev
This module don't have dependencies.
In a browser:
<script src="benchmarkjs.js"></script>
In Node.js:
var Benchmark = require('benchmarkjs');
Enable Node.js V8 native syntax for optimization check with this parameter:
node --allow-natives-syntax
Usage example:
var benchmarkjs = require('benchmarkjs');
benchmarkjs.options({
testTime: 4000
});
var bigArray1 = new Array(1000);
benchmarkjs('n < max', function () {
for (var n = 0, max = bigArray1.length; n < max; n++) {
bigArray1[n] = 0 | Math.random() * 1000;
}
});
var bigArray2 = new Array(1000);
benchmarkjs('n < hugeArray2.length', function () {
for (var n = 0; n < bigArray2.length; n++) {
bigArray2[n] = 0 | Math.random() * 1000;
}
});
console.log(benchmarkjs.results);
The result is similar to this:
[ { name: 'n < max', // test name
elapsed: 4395, // total time to test
checks: 2, // internal time checks
totalIterations: 484811, // total executions
persecondIterations: 110309, // execution per second
isOptimized: null, // have value only with node and the paramenter --allow-natives-syntax
diff: '0%' }, // difference with the best case
{ name: 'n < hugeArray2.length', // test name
elapsed: 4325, // total time to test
checks: 2, // internal time checks
totalIterations: 475535, // total executions
persecondIterations: 109950, // execution per second
isOptimized: null, // have value only with node and the paramenter --allow-natives-syntax
diff: '0.33%' } ] // difference with the best case
isOptimized can have these values:
1 - "optimized"
2 - "not optimized"
3 - "always optimized"
4 - "never optimized"
6 - "maybe deoptimized"
7 - "turbofan optimized"
FAQs
Easy bechmark framework for Javascript code
The npm package benchmarkjs receives a total of 2 weekly downloads. As such, benchmarkjs popularity was classified as not popular.
We found that benchmarkjs 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
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.