y.bind

JavaScript performance comparison

Test case created by Dav Glass

Info

https://github.com/yui/yui3/pull/320

Preparation code

<script src="http://yui.yahooapis.com/3.9.0pr1/yui/yui-min.js"></script>
 
<script>
Benchmark.prototype.setup = function() {
    var Y = YUI(),
    L = Y.Lang,
    noop = function() {},
    Ybind = function(f, c) {
        var xargs = arguments.length > 2 ?
                Y.Array(arguments, 2, true) : null;
        return function() {
            var fn = L.isString(f) ? c[f] : f,
                args = (xargs) ?
                    xargs.concat(Y.Array(arguments, 0, true)) : arguments;
            return fn.apply(c || fn, args);
        };  
    };
   
    function bind_(r,f,c){
        var xargs = arguments.length > 3 ?
                Y.Array(arguments, 3, true) : [],
            Noop = function () {
            },
            bound = function () {
                var fn = L.isString(f) ? c[f] : f,
                    inArgs = Y.Array(arguments, 0, true);            
                return fn.apply(this instanceof Noop ? this : c,
                    (r ? inArgs.concat(xargs) : xargs.concat(inArgs)));
            };
        if (L.isFunction(f)) {
            Noop.prototype = f.prototype;  
            bound.prototype = new Noop();
        }    
        return bound;
    };
   
    var newYbind = bind_(0, bind_, null, 0);
};
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
old Y.bind
var fn = Ybind(noop, window, 1, 2, 3, 4);
pending…
new Y.bind
var fn = newYbind(noop, window, 1, 2, 3, 4);
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:

0 comments

Add a comment