Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/janhancic/fasterforeach.shim
A hack to see if I can make a faster forEach shim.
https://github.com/janhancic/fasterforeach.shim
Last synced: 22 days ago
JSON representation
A hack to see if I can make a faster forEach shim.
- Host: GitHub
- URL: https://github.com/janhancic/fasterforeach.shim
- Owner: janhancic
- License: mit
- Created: 2014-02-02T02:03:10.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2014-02-15T13:53:17.000Z (over 10 years ago)
- Last Synced: 2024-04-14T19:15:47.268Z (7 months ago)
- Language: JavaScript
- Homepage: http://hancic.info/creating-a-faster-foreach-shim
- Size: 148 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# fasterForEach
A hack to see if I can make a faster forEach shim for IE8.## About
This is a hack that adds support for `Array#forEach` to IE8 but in a different way than the [ES5 shim](https://github.com/es-shims/es5-shim).This basically rewrites the item processor (callback you pass into forEach) into a regular `for` loop and executes that (as oposed to executing the callback on each iteration). The result is that instead of `1 + n` function invocations that you get with native or shimed `forEach` you get only two function invocations.
I created two nearly identical versions, the only difference is how the rewriten code gets executed. One uses `eval` and the other uses `new Function()`.
Testing shows that both versions are faster than the ES5 shim. However I only have access to a VM from [modern.ie](http://modern.ie) running on a Macbook Air. But please visit this [jsPerf test page](http://jsperf.com/faster-foreach-shim) and give it a spin so I can collect more data.
## Is it usable?
I haven't tested this in any real project, but in theory I don't see why it couldn't be used.## License
Licensed under MIT. See `LICENSE.md` file for details.