genericsize method

JavaScript performance comparison

Test case created

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.

Testing in unknown unknown
Test Ops/sec
wrapped function call
wrapFunc(that, bar);
pending…
created function call
newFunc(that, bar);
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment