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

multicore

v0.2.0

Published

A simple Javascript library for handling Workers.

Downloads

42

Readme

Multicore

A simple Javascript library for handling Web Workers.

Currently being developed. Only works on the web.

Progress so far:

  • Faster for arithmetic operations than ParallelJS. Test: Operating on a list of 100k elements, multiplying and reducing them to one value. Result: Multicore: ~200ms - ParallelJS ~20s
  • Now supports TypedArrays (and any kind of transferable) for futher increase in speed and memory use.

Installation

Use yarn or npm:

yarn add multicore --save
npm install --save multicore

This assumes that you’re using npm package manager with a module bundler like Webpack or Browserify to consume CommonJS modules.

Documentation

Usage

TLDR;
  • Use .data or, if you know size/type of array, a TypedArray function like .uInt8.
  • Then manipulate data by chaining API-methods: Multicore.data([1,2,3]).reduce((acc,val) => acc+val);
  • Retrieve the data from the instance promise: [...].reduce().map().then(result => { doSomething(result); })

Import Multicore

Using either:

const Multicore = require('multicore').default;
import Multicore from 'multicore';

Create an instance

Start an instance for data you wish you manipulate (can either be used as a constructor or with these static shorthand-methods):

Constructor

Create an instance with constructor and save it to a variable. The Constructor can also be subclassed as per ES6 classes.

const data = new Multicore([1,2,3]); // Constructor
Static converter-functions

Use the generic .data method to get the same behavior as with constructor.

Use any of the TypedArray functions to pass in an array and use parallelized conversion to convert it to a typed array internally, and thereby being able to use buffers internally. Recommended for large arrays containing integers or floats, or anytime you know your array will only contain numbers.

TypedArray functions for the different types: .int8, .int16, .int32, .uInt8, .uInt16, .uInt32, .float32, .float16.

const data = Multicore.data([1,2,3]); // Use for generic data.
const data = Multicore.uInt8([1,2,3); // Will convert array to typed-array and be able to utilize buffers internally

Start manipulating

// Manipulate saved instance
data.map(val => val*2)
  .map(val => val*3)
  .reduce((acc, val) => {
    return acc + val;
  })
  .then(result => {
    console.log(`The result is ${result}`);
  });

// The result is 37

// Direct manipulation and conversion
Multicore.uInt8([1,2,3])
    .map(val => val*2)
    .then(console.log); 

// [2,4,6]
  

Methods

A method receives only one argument, the current data being manipulated.

.spawn(fn)

Apply given function to current data. Usage:

const data = new Multicore(['a','b','c']);
data.spawn(data => {
    return data.join(',').toUpperCase();
});

// "A,B,C"

.map(fn)

Map over elements of array applying given function to every element. Similar to Javascript Array.map Usage:

const data = new Multicore([1,2,3]);
data.map(val => val*2);

// [2,4,6]

.reduce(fn, [accumulator = 0])

Applies a function against an accumulator and each element in the array in parallel to reduce it to a single value. Important: This function is optimized to run in parallel and needs your reduction operators to be associative, if your operators are not associative then use foldr() instead. Usage:

const data = new Multicore([1,2,3]);
data.reduce((acc, val) => {
    return acc + val;
  });

// 6

.foldr(fn, [accumulator = 0])

Applies a function against an accumulator and each element in the array in from left-to-right to reduce it to a single value. Similar to Javascript Array.reduce. Usage:

const data = new Multicore([1,2,3]);
data.foldr((acc, val) => {
    return acc - val;
  }, 0);

// -4

.filter(fn)

The filter method filters the data and keeps only elements that pass the test implemented by the provided function. Similar to Javascript Array.filter Usage:

const data = new Multicore([1,2,3]);
data.filter((val) => {
    return val > 2;
  });

// 3

More methods under development.

Work In Progress

Work that is currently underway and lives in feature-branches.

  • Adding full test-coverage.
  • Switching to babel-implementation and building minified-js-files for CDN.
  • Adding support for new operators: .parallel and .merge.

License

MIT