func-comparator
Advanced tools
+7
-112
@@ -1,2 +0,2 @@ | ||
| /* global performance */ | ||
| var Timer = require('neo-timer').Timer; | ||
@@ -7,3 +7,2 @@ var util = require('./util'); | ||
| function Comparator() { | ||
| this._funcs = {}; | ||
@@ -32,3 +31,2 @@ this._events = {}; | ||
| Comparator.prototype.set = function set(name, func) { | ||
| if (typeof name == 'object') { | ||
@@ -46,3 +44,2 @@ util.forEach(name, util.reverse(set.bind(this))); | ||
| Comparator.prototype.get = function(name) { | ||
| var self = this; | ||
@@ -74,3 +71,2 @@ if (Array.isArray(name)) { | ||
| Comparator.prototype.option = function(options) { | ||
| var self = this; | ||
@@ -88,3 +84,2 @@ util.forEach(options, function(value, key) { | ||
| Comparator.prototype.async = function(bool) { | ||
| this._options.async = bool === false ? false : true; | ||
@@ -98,3 +93,2 @@ return this; | ||
| Comparator.prototype.concurrency = function(concurrency) { | ||
| this._options.concurrency = concurrency; | ||
@@ -109,3 +103,2 @@ return this; | ||
| Comparator.prototype.times = function(times) { | ||
| if (times) { | ||
@@ -128,3 +121,2 @@ this._options.times = times; | ||
| Comparator.prototype.start = function() { | ||
| var self = this; | ||
@@ -172,3 +164,2 @@ var funcs = self._funcs; | ||
| function whilist() { | ||
| var started = 0; | ||
@@ -183,3 +174,2 @@ var called = 0; | ||
| function iterate() { | ||
| if (!end && started < times) { | ||
@@ -206,3 +196,2 @@ iterator(started++, function(err) { | ||
| function iterator(count, callback) { | ||
| var index = 0; | ||
@@ -213,4 +202,5 @@ var called = 0; | ||
| var key = sample[index++]; | ||
| var timer = getTimer().init().start(); | ||
| timer.init().start(); | ||
| funcs[key](function(err) { | ||
| // s -> μs | ||
| var diff = timer.diff(); | ||
@@ -239,3 +229,2 @@ if (count >= skip) { | ||
| Comparator.prototype.on = function on(key, callback) { | ||
| if (typeof key == 'object') { | ||
@@ -251,3 +240,2 @@ util.forEach(key, util.reverse(on)); | ||
| Comparator.prototype.once = function once(key, callback) { | ||
| if (typeof key == 'object') { | ||
@@ -264,3 +252,2 @@ util.forEach(key, util.reverse(once)); | ||
| Comparator.prototype.emit = function emit(key, err, res) { | ||
| var events = this._events[key] || []; | ||
@@ -286,3 +273,2 @@ if (!events.length) { | ||
| Comparator.prototype.result = function result(callback) { | ||
| var results = {}; | ||
@@ -369,101 +355,7 @@ var opts = this._options; | ||
| function getTimer() { | ||
| if (objectTypes[typeof process] && process && process.hrtime) { | ||
| return new NodeTimer(); | ||
| } | ||
| if (objectTypes[typeof performance] && performance && performance.now) { | ||
| return new PerformanceTimer(); | ||
| } | ||
| if (objectTypes[typeof Date]) { | ||
| return new DateTimer(); | ||
| } | ||
| return new Timer(); | ||
| } | ||
| Comparator.prototype.getTimer = getTimer; | ||
| // process.hrtime | ||
| function NodeTimer() { | ||
| this._startTime = null; | ||
| this._diff = null; | ||
| } | ||
| NodeTimer.prototype.init = function() { | ||
| this._startTime = null; | ||
| this._diff = null; | ||
| return this; | ||
| }; | ||
| NodeTimer.prototype.start = function () { | ||
| this._startTime = process.hrtime(); | ||
| return this; | ||
| }; | ||
| NodeTimer.prototype.diff = function() { | ||
| var diff = process.hrtime(this._startTime); | ||
| // ns | ||
| this._diff = diff[0] * 1e9 + diff[1]; | ||
| // μs | ||
| return this._diff / 1000; | ||
| }; | ||
| // performance.now | ||
| function PerformanceTimer() { | ||
| this._startTime = null; | ||
| this._diff = null; | ||
| } | ||
| PerformanceTimer.prototype.init = function() { | ||
| this._startTime = null; | ||
| this._diff = null; | ||
| return this; | ||
| }; | ||
| PerformanceTimer.prototype.start = function () { | ||
| this._startTime = performance.now(); | ||
| return this; | ||
| }; | ||
| PerformanceTimer.prototype.diff = function() { | ||
| // ms | ||
| this._diff = performance.now() - this._startTime; | ||
| // μs | ||
| return this._diff * 1000; | ||
| }; | ||
| function DateTimer() { | ||
| this._startTime = null; | ||
| this._diff = null; | ||
| } | ||
| DateTimer.prototype.init = function() { | ||
| this._startTime = null; | ||
| this._diff = null; | ||
| return this; | ||
| }; | ||
| DateTimer.prototype.start = function () { | ||
| this._startTime = new Date().getTime(); | ||
| return this; | ||
| }; | ||
| DateTimer.prototype.diff = function() { | ||
| // ms | ||
| this._diff = new Date().getTime() - this._startTime; | ||
| // μs | ||
| return this._diff * 1000; | ||
| }; | ||
| function resolveDecimal(num) { | ||
| return Math.floor(100 * num) / 100; | ||
@@ -478,2 +370,5 @@ } | ||
| (function() { | ||
| 'use strict'; | ||
| var comparator = new Comparator(); | ||
@@ -480,0 +375,0 @@ if (objectTypes[typeof module] && module && module.exports) { |
+4
-2
| { | ||
| "name": "func-comparator", | ||
| "version": "0.6.1", | ||
| "version": "0.6.2", | ||
| "description": "func-comparator is intended functions speed comparison", | ||
@@ -18,3 +18,5 @@ "main": "index.js", | ||
| "homepage": "https://github.com/suguru03/func-comparator", | ||
| "dependencies": {}, | ||
| "dependencies": { | ||
| "neo-timer": "^0.2.0" | ||
| }, | ||
| "devDependencies": { | ||
@@ -21,0 +23,0 @@ "async": "^0.9.0", |
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
226840
-0.69%1
Infinity%5816
-1.12%+ Added
+ Added