Skip to content
A precompiled forEach, unrolled for faster runtime performance.
JavaScript CSS Shell
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

April 24th 2012

Project discontinued in favour of 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.


  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.


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

// Object
  foo: 'foo',
  bar: 'bar',
  baz: 'baz'
Something went wrong with that request. Please try again.