https://github.com/jamiemason/peach.js
A precompiled forEach, unrolled for faster runtime performance.
https://github.com/jamiemason/peach.js
Last synced: 2 months ago
JSON representation
A precompiled forEach, unrolled for faster runtime performance.
- Host: GitHub
- URL: https://github.com/jamiemason/peach.js
- Owner: JamieMason
- Created: 2011-10-05T21:33:33.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2014-02-17T16:02:57.000Z (over 11 years ago)
- Last Synced: 2024-10-18T19:34:50.035Z (8 months ago)
- Language: JavaScript
- Homepage:
- Size: 289 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
**April 24th 2012**
Project discontinued in favour of [https://github.com/bestiejs/lodash](https://github.com/bestiejs/lodash) which has implemented the same technique of function compilation and applied it to underscore.js. Thanks goes to [@jdalton](https://github.com/jdalton) for his earlier help [[1](http://jsperf.com/precompiled-each-iterators/2#comment-1)] [[2](http://jsperf.com/precompiled-each-iterators/6#comment-1)] with this project.
---
> **`pEach(iterator:Function, [timesToUnroll:Number]):Function` takes functions you would pass to an iterator such as [_.each()](http://documentcloud.github.com/underscore/#each) or [Array.forEach](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/forEach) and returns another which is optimised for runtime performance.**
>
> ### How?
>
> 1. [Loop unwinding](http://en.wikipedia.org/wiki/Loop_unwinding) is applied.
> 1. The contents of your function are extracted and combined with the unrolled loop.
> 1. The loop construct used is the [fastest loop for the browser the user is using](http://jsperf.com/different-kinds-of-loop/2).
>
> ### 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'
> });