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-max

v0.5.1

Published

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

Downloads

6,603

Readme

fast-max

:fire: The Quickest Way to get the Maximum Value of an Array of Numbers (Typed or Untyped)

install

npm install fast-max

why is it so much faster?

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

usage

getting maximum value of a normal array

const fastMax = require("fast-max"); // or import max from "fast-max";

const result = fastMax([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
// result is 10

getting maximum value of a typed array

const fastMax = require("fast-max");

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

setting theoretical maximum

If you know that an array's values can't exceed a specific number, you can set the theoretical_max.

const fastMax = require("fast-max");

const numbers = [0, 9, 4, 2, 10, ...]);
const result = fastMax(numbers, { theoretical_max: 10 });
// result is 10

no data value

If you want to ignore one or more specific values, you can set the no_data value.

const fastMax = require("fast-max");

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

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

performance tests

Here are test results comparing fast-max to two other popular libraries underscore and lodash. Tests have been conducted by creating an array of ten million random numbers from zero to the maximum theoretical value of the typed array. | array type | library | average duration in milliseconds | | ---------- | ------- | -------------------------------- | | Int8Array | fast-max | < 1 | | Int8Array | lodash | 20.9 | | Int8Array | underscore | 14.3 | | Uint8Array | fast-max | 0.1 | | Uint8Array | lodash | 21.4 | | Uint8Array | underscore | 14.3 | | Int16Array | fast-max | 1.4 | | Int16Array | lodash | 21 | | Int16Array | underscore | 13.7 | | Uint16Array | fast-max | 1.9 | | Uint16Array | lodash | 20.9 | | Uint16Array | underscore | 13.8 | | Int32Array | fast-max | 31.2 | | Int32Array | lodash | 21.2 | | Int32Array | underscore | 14.2 | | Uint32Array | fast-max | 109.8 | | Uint32Array | lodash | 73.3 | | Uint32Array | underscore | 15 | | BigInt64Array | fast-max | 115.4 | | BigInt64Array | lodash | 237.5 | | BigInt64Array | underscore | 222.4 | | BigUint64Array | fast-max | 113.9 | | BigUint64Array | lodash | 236.4 | | BigUint64Array | underscore | 219.7 |