
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
measure-speed
Advanced tools
This is a module for measuring the average or median speed of functions.
This function takes as arguments a function, options object and a callback. The callback is called with the error (null if everything is ok) and a number of milliseconds.
var measureSpeed = require('measure-speed');
measureSpeed(function () {
var a = [2, 5, 6, 3, 7, 9, 2, 3, 5, 6, 34, 234, 5, 23, 523, 4, 5, 23, 4, 5, 23, 4, 5, 2, 34];
a.sort();
},
{ samples: 1000 },
function (err, ms) {
// ms is the number of milliseconds. The resolution is in microseconds
});
The function runs a certain number of times (default 100), every run is timed, the timings are sorted and the biggest and smallest values are removed. The result is the average of the remainings. The options are:
Measure speed works also if the function returns a promise.
measureSpeed(function () {
return Promise(function (resolve, reject) {
setTimeout(resolve, 100);
});
},
{ samples: 1000 },
function (err, ms) {
// ms is the number of milliseconds. The resolution is in microseconds
});
Or a callback
measureSpeed(function (callback) {
myfunc(callback);
},
{ samples: 1000 },
function (err, ms) {
// ms is the number of milliseconds. The resolution is in microseconds
});
This allows to run more tests and output the difference in timings:
var measureSpeedCompare = require('measure-speed/compare');
measureSpeedCompare([func1, func2, func3],
{ samples: 1000 }, // same options as measureSpeed
function (err, results) {
// results.timings is a list of timings
// results.timingsRel every timing divided by the first one
// results.timingsPerc every timing divided by the first one (and then multiplied by 100)
});
FAQs
Measure speed of sync/async functions
We found that measure-speed 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 how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.