npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fast-min

v0.4.0

Published

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

Downloads

3,707

Readme

fast-min

:fire: 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 one or more specific values, 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

const result = fastMax(numbers, { no_data: [5, 99] });
// result is now 7

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 | 23.2 | | Int8Array | underscore | 10.3 | | Uint8Array | fast-min | < 1 | | Uint8Array | lodash | 23.2 | | Uint8Array | underscore | 10.3 | | Int16Array | fast-min | 0.4 | | Int16Array | lodash | 23.5 | | Int16Array | underscore | 10.4 | | Uint16Array | fast-min | 0.8 | | Uint16Array | lodash | 23.5 | | Uint16Array | underscore | 10.6 | | Int32Array | fast-min | 65.6 | | Int32Array | lodash | 23.5 | | Int32Array | underscore | 11 | | Uint32Array | fast-min | 139.7 | | Uint32Array | lodash | 27.2 | | Uint32Array | underscore | 16.4 | | BigInt64Array | fast-min | 56.1 | | BigInt64Array | lodash | 78.8 | | BigInt64Array | underscore | 63.9 | | BigUint64Array | fast-min | 55.9 | | BigUint64Array | lodash | 122.1 | | BigUint64Array | underscore | 114.9 |