reducibles
JavaScript performance comparison
Info
Comparing clojure like reducers to native implementations and Lo-Dash
Preparation code
<script src="https://raw.github.com/bestiejs/lodash/v0.8.1/lodash.js"></script>
<script>
Benchmark.prototype.setup = function() {
var _ = window._;
// Some helper functions we'll use
function increment(x) { return x + 1 }
function isOdd(n) { return n % 2 }
function sum(x, y) { return (x || 0) + (y || 0) }
function reduced(value) {
return Object.create(reduced.prototype, {
value: { value: value }
})
}
reduced.is = function is(value) {
return value && value.constructor === reduced
}
function reducible(reduce) {
return { reduce: reduce }
}
function reducer(process) {
return function(f, items) {
return reducible(function(next, start) {
return reduce(function(result, item) {
var value = process(f, item, reduced)
var ended = false //reduced.is(value)
value = ended ? value.value : value
result = value === undefined ? result : next(result, value)
return ended ? reduced(result) : result
}, items, start)
})
}
}
function reduce(f, reducible, start) {
return reducible.reduce(f, start)
}
var filter = reducer(function(f, item) {
if (f(item)) return item
})
var map = reducer(function(f, item) {
return f(item)
})
function into(reducible, target) {
// reduce reducible and colelect it's
// items into array which we return after.
return reduce(function(result, item) {
result.push(item)
return result
}, reducible, target || [])
}
function range(from, to) {
var values = []
while (from < to) values.push(from++)
return values
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
array |
|
pending… |
reducible |
|
pending… |
lodash |
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:
- Revision 1: published by Irakli Gozilishvili
- Revision 2: published
- Revision 3: published by Irakli Gozilishvili
- Revision 4: published
- Revision 5: published by John-David Dalton
- Revision 6: published
- Revision 7: published by Jakeb
0 comments