genericsize method
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
var method = function (foo) {
this.foo = foo;
return this;
};
function genericsize (method) {
var source = method.toString().match(/^function\s?(?:[^( ]+\s)?\(([^)]*)\)\s?\{((?:.|\n)*)\}$/),
parts = source[1].split(/\s*,\s*/),
body = source[2].replace(/(^|\W)this(\W|$)/g, "$1that$2");
parts.unshift("that");
parts.push(body);
return Function.apply(null, parts);
}
var slice = Array.prototype.slice;
var wrapFunc = function (that) {
return method.apply(that, slice.call(arguments, 1));
};
var newFunc = genericsize(method);
var that = {},
bar = "bar";
};
Benchmark.prototype.teardown = function() {
var that = {};
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
wrapped function call |
|
pending… |
created function call |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments