Comparing version 0.0.1 to 0.0.2
@@ -7,3 +7,6 @@ module.exports = { | ||
"globals": { | ||
"chronolite": true | ||
"chronolite": true, | ||
"test": true, | ||
"expect": true, | ||
"require": true, | ||
}, | ||
@@ -10,0 +13,0 @@ "extends": "eslint:recommended", |
@@ -0,4 +1,3 @@ | ||
module.exports = class chronolite { | ||
export default class chronolite { | ||
constructor() { | ||
@@ -14,4 +13,4 @@ this.defaultIterations = 20; | ||
} | ||
if (obj.fn === undefined) { | ||
return [false, "function (fn) is undefined: " + objStr]; | ||
if (typeof obj.fn !== "function") { | ||
return [false, "function (fn) is not a function type: " + objStr]; | ||
} | ||
@@ -21,4 +20,5 @@ if (obj.fnArgs !== undefined && !Array.isArray(obj.fnArgs)) { | ||
} | ||
if (obj.binding !== undefined && typeof obj.binding !== obj) { | ||
return [false, "binding is defined but not an object : " + objStr]; | ||
if (obj.binding !== undefined && typeof obj.binding !== "object") { | ||
return [false, "binding is defined but not an object (got " + | ||
typeof obj + ") with value: " + objStr]; | ||
} | ||
@@ -30,3 +30,2 @@ return [true, ""]; | ||
// Time code | ||
_setup(fnToTime) { | ||
@@ -163,2 +162,2 @@ const valid = this.validInput(fnToTime); | ||
} | ||
}; |
{ | ||
"name": "chronolite", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"source": "chronolite.js", | ||
@@ -8,8 +8,26 @@ "main": "dist/chronolite.js", | ||
"scripts": { | ||
"build": "microbundle" | ||
"build": "microbundle", | ||
"test": "jest", | ||
"test:coverage": "jest --coverage" | ||
}, | ||
"keywords": [ | ||
"performance", | ||
"benchmark", | ||
"timing", | ||
"timer", | ||
"perf", | ||
"compare", | ||
"functions" | ||
], | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:JamesMilnerUK/chronolite.git" | ||
}, | ||
"bugs": "https://github.com/JamesMilnerUK/chronolite/issues", | ||
"devDependencies": { | ||
"eslint": "^4.16.0", | ||
"jest": "^22.4.3", | ||
"microbundle": "^0.4.3" | ||
} | ||
} |
@@ -1,1 +0,69 @@ | ||
# chronolite | ||
# chronolite 🕰️ | ||
chronolite is a microlibrary for timing, comparing and benchmarking JavaScript functions. It supports both synchronous and asynchronous functions. Common use cases include performance benchmarking for a function, and benchmarking multiple functions against each other. | ||
## Install | ||
For npm: | ||
``` npm install chronolite ``` | ||
For yarn: | ||
``` yarn add chronolite ``` | ||
## Usage | ||
chronolite has 4 core methods: | ||
* **time** - Return the running time of a synchronous function | ||
* **timeAsync** - Return the running time of a async function (function must return a promise) | ||
* **compare** - Find the fastest function out of an array of functions | ||
* **compareAsync** - Find the fastest function out of an array of async functions | ||
Methods take objects or arrays of objects of the following schema: | ||
```javascript | ||
{ | ||
id: "someFunction", // - string (optional) | ||
binding: null // object (optional) - The object to bind the function to (defaults to null) | ||
fn: someFunc, // function | ||
fnArgs: [1, 2, 3], // array - The array of arguments | ||
} | ||
``` | ||
Here is an example of using the time method: | ||
```javascript | ||
var timer = new chronolite(); | ||
var fn = function(input) { | ||
// Synthetic wait | ||
const ms = input * (Math.random() * 1); | ||
const start = Date.now(); | ||
let now = start; | ||
while (now - start < ms) { | ||
now = Date.now(); | ||
} | ||
return "finished"; | ||
}; | ||
var arg = [10]; | ||
var iterations = 15; | ||
var time = timer.time({ | ||
fn: first, | ||
fnArgs: arg, | ||
}, iterations); | ||
console.log("time", time.averageTime); | ||
``` | ||
## License | ||
MIT |
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
44788
14
0
552
69
0
3