JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 8659
  • Score
    100M100P100Q139767F
  • License CC0-1.0

Quickest Way to get the Minimum Value of an Array of Numbers (Typed or Untyped)

Package Exports

  • fast-min
  • fast-min/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (fast-min) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

fast-min

🔥 The Quickest Way to get the Minimum Value of an Array of Numbers (Typed or Untyped)

install

npm install fast-min

why is it so much faster?

This library excels with typed arrays. It takes into account the theoretical minimum of a typed array. For example, if you have a Uint8Array, it's not possible for a minimum value to be less than zero, so if we encounter a 0 in the array, we can stop searching for the minimum value.

usage

getting minimum value of a normal array

import fastMin from 'fast-min';

const result = fastMin([0, -1, -2, -3, -4, -5]);
// result is -5

getting minimum value of a typed array

import fastMin from 'fast-min';

const pixel_values = Uint8Array.from([0, 128, 255, 34, ...]);
const result = fastMin(pixel_values);
// result is 0

no data value

If you want to ignore a specific value, you can set the no_data value.

import fastMin from 'fast-min';

const numbers = [99, 0, 7, 99, 5, ...]);
const result = fastMin(numbers, { no_data: 0 });
// result is 5

performance tests

Here are test results comparing fast-min to two other popular libraries underscore and lodash. 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 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