Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A precompiled forEach, unrolled for faster runtime performance.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 tests
Octocat-spinner-32 README.md
Octocat-spinner-32 build.sh
Octocat-spinner-32 peach-min.js
Octocat-spinner-32 peach.js
README.md

April 24th 2012

Project discontinued in favour of https://github.com/bestiejs/lodash which has implemented the same technique of function compilation and applied it to underscore.js. Thanks goes to @jdalton for his earlier help [1] [2] with this project.


pEach(iterator:Function, [timesToUnroll:Number]):Function takes functions you would pass to an iterator such as _.each() or Array.forEach and returns another which is optimised for runtime performance.

How?

  1. Loop unwinding is applied.
  2. The contents of your function are extracted and combined with the unrolled loop.
  3. The loop construct used is the fastest loop for the browser the user is using.

Example

Take an iterator that you would pass to something like _.each

_.each(['foo','bar','baz'], function (num, key, collection) {
  console.log(num, key, collection, this);
});

Pass it to pEach

var optimised = pEach(function (num, key, collection) {
  console.log(num, key, collection, this);
});

and use the optimised function instead

// Array
optimised(['foo','bar','baz']);

// Object
optimised({
  foo: 'foo',
  bar: 'bar',
  baz: 'baz'
});
Something went wrong with that request. Please try again.