Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jalik/benchmark

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jalik/benchmark - npm Package Compare versions

Comparing version 2.0.1 to 2.0.2

59

dist/benchmark.js
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -11,13 +10,7 @@ value: true

exports.logBenchmarkResult = logBenchmarkResult;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _measure = require("./measure");
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
/**

@@ -32,11 +25,10 @@ * Measures the execution times of several async functions.

var promises = [];
var measures = {}; // Measure functions synchronously.
var measures = {};
// Measure functions synchronously.
var entries = Object.entries(asyncJobs);
var _loop = function _loop(i) {
var _entries$i = (0, _slicedToArray2["default"])(entries[i], 2),
name = _entries$i[0],
asyncFunc = _entries$i[1];
name = _entries$i[0],
asyncFunc = _entries$i[1];
promises.push((0, _measure.measure)(asyncFunc, iterations).then(function (result) {

@@ -46,7 +38,5 @@ return [name, result];

};
for (var i = 0; i < entries.length; i += 1) {
_loop(i);
}
return Promise.all(promises).then(function (results) {

@@ -56,9 +46,9 @@ // Sort result from fastest to slowest.

return a[1].total - b[1].total;
}); // Assign rank to each function result.
});
// Assign rank to each function result.
sortedResults.forEach(function (_ref, index) {
var _ref2 = (0, _slicedToArray2["default"])(_ref, 2),
name = _ref2[0],
result = _ref2[1];
name = _ref2[0],
result = _ref2[1];
measures[name] = _objectSpread(_objectSpread({}, result), {}, {

@@ -71,2 +61,3 @@ rank: index + 1

}
/**

@@ -78,23 +69,21 @@ * Measures the execution times of several functions.

*/
function benchmarkSync(jobs) {
var iterations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
var result = {}; // Measure functions synchronously.
var result = {};
// Measure functions synchronously.
var entries = Object.entries(jobs);
for (var i = 0; i < entries.length; i += 1) {
var _entries$i2 = (0, _slicedToArray2["default"])(entries[i], 2),
name = _entries$i2[0],
func = _entries$i2[1];
name = _entries$i2[0],
func = _entries$i2[1];
result[name] = (0, _measure.measureSync)(func, iterations);
} // Sort result from fastest to slowest.
}
// Sort result from fastest to slowest.
var sortedResult = Object.entries(result).sort(function (a, b) {
return a[1].total - b[1].total;
}); // Assign rank to each function result.
});
// Assign rank to each function result.
sortedResult.forEach(function (r, index) {

@@ -105,2 +94,3 @@ result[r[0]].rank = index + 1;

}
/**

@@ -110,4 +100,2 @@ * Displays benchmark result in the console.

*/
function logBenchmarkResult(result) {

@@ -119,8 +107,9 @@ // Sort result from fastest to slowest.

return a[1] - b[1];
}); // Display each result to console.
});
// Display each result to console.
sortedResult.forEach(function (entry, index) {
var mr = result[entry[0]];
var pre = index > 0 && index < sortedResult.length ? '\r\n' : ''; // eslint-disable-next-line no-console
var pre = index > 0 && index < sortedResult.length ? '\r\n' : '';
// eslint-disable-next-line no-console
console.info("".concat(pre, "#").concat(mr.rank, " ").concat(entry[0]));

@@ -127,0 +116,0 @@ (0, _measure.logMeasureResult)(mr);

@@ -42,5 +42,3 @@ "use strict";

});
var _benchmark = require("./benchmark");
var _measure = require("./measure");

@@ -6,8 +6,6 @@ "use strict";

});
exports.logMeasureResult = logMeasureResult;
exports.measure = measure;
exports.measureSync = measureSync;
exports.logMeasureResult = logMeasureResult;
var _utils = require("./utils");
/*

@@ -46,3 +44,2 @@ * The MIT License (MIT)

var promises = [];
var _loop = function _loop(i) {

@@ -56,7 +53,5 @@ var time = (0, _utils.currentMillis)();

};
for (var i = 0; i < iterations; i += 1) {
_loop(i);
}
return Promise.all(promises).then(function (times) {

@@ -66,2 +61,3 @@ return (0, _utils.calculateStats)(times);

}
/**

@@ -73,8 +69,5 @@ * Measures the execution times of a function.

*/
function measureSync(func) {
var iterations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
var times = [];
for (var i = 0; i < iterations; i += 1) {

@@ -85,5 +78,5 @@ times[i] = (0, _utils.currentMillis)();

}
return (0, _utils.calculateStats)(times);
}
/**

@@ -93,4 +86,2 @@ * Displays measure result in the console.

*/
function logMeasureResult(result) {

@@ -97,0 +88,0 @@ // eslint-disable-next-line no-console

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -17,5 +16,3 @@ value: true

exports.sum = sum;
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
/*

@@ -55,2 +52,3 @@ * The MIT License (MIT)

}
/**

@@ -71,4 +69,2 @@ * Calculates statistics of several times.

*/
function calculateStats(times) {

@@ -78,11 +74,11 @@ // eslint-disable-next-line no-use-before-define

var average = total / times.length;
var ips = calculateIps(total, times.length); // eslint-disable-next-line no-use-before-define
var ips = calculateIps(total, times.length);
// eslint-disable-next-line no-use-before-define
var ipsRounded = roundToNearest(ips);
var ipsAccuracy = ips - ipsRounded; // eslint-disable-next-line no-use-before-define
var med = median(times); // eslint-disable-next-line no-use-before-define
var fastest = min(times); // eslint-disable-next-line no-use-before-define
var ipsAccuracy = ips - ipsRounded;
// eslint-disable-next-line no-use-before-define
var med = median(times);
// eslint-disable-next-line no-use-before-define
var fastest = min(times);
// eslint-disable-next-line no-use-before-define
var slowest = max(times);

@@ -102,2 +98,3 @@ return {

}
/**

@@ -107,7 +104,6 @@ * Returns the current time in milliseconds (with floating precision if supported).

*/
function currentMillis() {
return typeof performance !== 'undefined' && 'now' in performance ? performance.now() : Date.now();
}
/**

@@ -118,4 +114,2 @@ * Returns the formatted time.

*/
function formatMillis(time) {

@@ -125,2 +119,3 @@ // eslint-disable-next-line no-restricted-globals

}
/**

@@ -131,8 +126,5 @@ * Returns the maximal value of numbers.

*/
function max(numbers) {
if (numbers.length === 0) return null;
var num = -Infinity;
for (var i = 0; i < numbers.length; i += 1) {

@@ -143,5 +135,5 @@ if (numbers[i] > num) {

}
return num;
}
/**

@@ -152,8 +144,5 @@ * Returns the median value of numbers.

*/
function median(numbers) {
if (numbers.length === 0) return null;
var sortedNumbers = (0, _toConsumableArray2["default"])(numbers);
for (var i = 0; i < numbers.length; i += 1) {

@@ -164,3 +153,2 @@ if (typeof numbers[i] === 'number') {

}
sortedNumbers.sort();

@@ -170,2 +158,3 @@ var half = Math.floor(sortedNumbers.length / 2);

}
/**

@@ -176,8 +165,5 @@ * Returns the minimal value of numbers.

*/
function min(numbers) {
if (numbers.length === 0) return null;
var num = Infinity;
for (var i = 0; i < numbers.length; i += 1) {

@@ -188,5 +174,5 @@ if (numbers[i] < num) {

}
return num;
}
/**

@@ -198,4 +184,2 @@ * Returns the nearest number

*/
function roundToNearest(number) {

@@ -208,2 +192,3 @@ var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;

}
/**

@@ -214,8 +199,5 @@ * Returns the sum of numbers.

*/
function sum(numbers) {
if (numbers.length === 0) return null;
var total = 0;
for (var i = 0; i < numbers.length; i += 1) {

@@ -226,4 +208,3 @@ if (typeof numbers[i] === 'number') {

}
return total;
}
{
"name": "@jalik/benchmark",
"version": "2.0.1",
"version": "2.0.2",
"description": "Utilities to benchmark code.",

@@ -34,3 +34,3 @@ "license": "MIT",

"prepublishOnly": "npm test",
"test": "jest --passWithNoTests"
"test": "jest --passWithNoTests --coverage=true"
},

@@ -42,16 +42,17 @@ "files": [

"dependencies": {
"@babel/runtime": "^7.15.4"
"@babel/runtime": "^7.19.4"
},
"devDependencies": {
"@babel/cli": "^7.15.7",
"@babel/core": "^7.15.5",
"@babel/plugin-transform-runtime": "^7.15.0",
"@babel/preset-env": "^7.15.6",
"eslint": "^7.32.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-jest": "^24.4.2",
"jest": "^27.2.1",
"typescript": "^4.4.3"
"@babel/cli": "^7.19.3",
"@babel/core": "^7.19.3",
"@babel/plugin-transform-runtime": "^7.19.1",
"@babel/preset-env": "^7.19.4",
"@jest/globals": "^29.2.1",
"eslint": "^8.25.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^27.1.3",
"jest": "^29.2.1",
"typescript": "^4.8.4"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc