Skip to content

Commit

Permalink
you can now pass in theoretical_min
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielJDufour committed May 24, 2021
1 parent d07aa60 commit ada11ea
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 39 deletions.
48 changes: 24 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,27 @@ Here are test results comparing fast-min to two other popular libraries undersco
Tests have been conducted by creating an array of ten million random numbers from the lowest to the highest theoretical value of the typed array.
| array type | library | average duration in milliseconds |
| ---------- | ------- | -------------------------------- |
| Int8Array | fast-min | **< 1** |
| Int8Array | lodash | 20.9 |
| Int8Array | underscore | 12.4 |
| Uint8Array | fast-min | **11.3** |
| Uint8Array | lodash | 23.5 |
| Uint8Array | underscore | 12.2 |
| Int16Array | fast-min | **0.5** |
| Int16Array | lodash | 23.6 |
| Int16Array | underscore | 13.3 |
| Uint16Array | fast-min | **13.2** |
| Uint16Array | lodash | 20.5 |
| Uint16Array | underscore | 13.5 |
| Int32Array | fast-min | **15.4** |
| Int32Array | lodash | 20.9 |
| Int32Array | underscore | 12.3 |
| Uint32Array | fast-min | **12.5** |
| Uint32Array | lodash | 60.9 |
| Uint32Array | underscore | 14.4 |
| BigInt64Array | fast-min | **244.2** |
| BigInt64Array | lodash | 257 |
| BigInt64Array | underscore | 245.3 |
| BigUint64Array | fast-min | **200.1** |
| BigUint64Array | lodash | 204.9 |
| BigUint64Array | underscore | 198 |
| Int8Array | fast-min | **0.1** |
| Int8Array | lodash | 20.7 |
| Int8Array | underscore | 14.9 |
| Uint8Array | fast-min | **11.5** |
| Uint8Array | lodash | 22.1 |
| Uint8Array | underscore | 12.6 |
| Int16Array | fast-min | **0.6** |
| Int16Array | lodash | 21.9 |
| Int16Array | underscore | 12.4 |
| Uint16Array | fast-min | **12.2** |
| Uint16Array | lodash | 21.2 |
| Uint16Array | underscore | 12.5 |
| Int32Array | fast-min | **13.1** |
| Int32Array | lodash | 20.6 |
| Int32Array | underscore | 12.6 |
| Uint32Array | fast-min | **12.7** |
| Uint32Array | lodash | 66.6 |
| Uint32Array | underscore | 15.3 |
| BigInt64Array | fast-min | **247.6** |
| BigInt64Array | lodash | 253 |
| BigInt64Array | underscore | 241.6 |
| BigUint64Array | fast-min | **194.5** |
| BigUint64Array | lodash | 206.1 |
| BigUint64Array | underscore | 205.4 |
20 changes: 5 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
const THEORETICAL_MINIMUMS = {
Array: null,
Int8Array: -128, // Math.pow(-2, 8 - 1)
Uint8Array: 0,
Uint8ClampedArray: 0,
Int16Array: -32768, // Math.pow(-2, 16 - 1)
Uint16Array: 0,
Int32Array: -2147483648, // Math.pow(-2, 32 - 1)
Uint32Array: 0,
// skipping Float32Array and Float64Array because it appears to be platform dependent
BigInt64Array: -9223372036854776000, // Math.pow(-2, 63)
BigUint64Array: 0,
};
const getTheoreticalMin = require("typed-array-ranges/get-min");

module.exports = function fastMin(
numbers,
{ debug = false, no_data = undefined } = {
{ debug = false, no_data = undefined, theoretical_min = undefined } = {
debug: false,
no_data: undefined,
theoretical_min: undefined,
}
) {
if (debug)
Expand All @@ -38,7 +27,8 @@ module.exports = function fastMin(

if (debug) console.log("[fast-min] constructor:", numbers.constructor.name);

let theoretical_min = THEORETICAL_MINIMUMS[numbers.constructor.name];
if (theoretical_min === undefined)
theoretical_min = getTheoreticalMin(numbers.constructor.name);
if (debug) console.log("[fast-min] theoretical minimunm is", theoretical_min);
if (theoretical_min) {
if (no_data !== undefined) {
Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,8 @@
"flug": "^1.1.0",
"lodash.min": "^4.0.1",
"underscore": "^1.13.1"
},
"dependencies": {
"typed-array-ranges": "^0.0.0"
}
}

0 comments on commit ada11ea

Please sign in to comment.