myumntyt
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
Function.prototype.curry = function() {
var fn = this,
_len, _len = len = arguments.length,
args = Array(len);
while (len--) args[len] = arguments[len];
return function() {
var i = 0,
_args = args.slice(),
len = arguments.length;
while (i < len) _args[_len + i] = arguments[i++];
return fn.apply(this, _args)
}
}
Function.prototype.curry2 = function(obj, that) {
var fn = this,
arg1 = Object(obj),
izthat = arguments.length > 1;
return function() {
var key, len = arguments.length,
arg2 = Array(len);
while (len--) arg2[len] = arguments[len];
for (key in arg1) key >>> 0 == key && arg2.splice(key, 0, arg1[key]);
return fn.apply(izthat ? that : this, arg2)
}
}
var slice = [].slice;
Function.prototype.curry3 = function(obj, that) {
var fn = this,
arg1 = slice.call(obj),
izthat = arguments.length > 1;
return function() {
var args = arg1.slice(),
len = arguments.length,
i, cur = i = 0;
while (i < len) {
while (args[cur] !== void 0) cur++;
args[cur++] = arguments[i++]
}
return fn.apply(izthat ? that : this, args)
}
}
function fn(q, w, e, r, t, y) {
return q + w + e + r + t + y
}
fn1 = fn.curry(1, 1, 1)
fn2 = fn.curry2({
1: 1,
3: 1,
5: 1
})
fn3 = fn.curry3([, 1, , 1, , 1])
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
fn1 |
|
pending… |
fn2 |
|
pending… |
fn3 |
|
pending… |
fn1 run |
|
pending… |
fn2 run |
|
pending… |
fn3 run |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments