Knockout Secure Binding (master)

JavaScript performance comparison

Test case created by Brian M Hunt

Info

Compare performance of Knockout Secure Binding (master) to Knockout regular bindings

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="//ajax.aspnetcdn.com/ajax/knockout/knockout-3.0.0.debug.js"></script>
<script src="//rawgithub.com/brianmhunt/knockout-secure-binding/master/dist/knockout-secure-binding.js"></script>

 
<script>
Benchmark.prototype.setup = function() {
    var original_binder, ksb_options, ksb_binder, context, protohtml, protoref;
   
    original_binder = ko.bindingProvider.instance;
    ksb_options = {
        attribute: "data-bind",
        globals: {
          b: ko.observable(true)
        }
      };
    ksb_binder = new ko.secureBindingsProvider(ksb_options);
    context = {
        a: ko.observable("var a"),
        c: ko.observableArray([1, 2, 3, 4, 5]),
        d: function () { return [function() { return 'dv' }] },
      };
   
    // access a global from Knockout proper
    window.b = ko.observable(true);
   
    protohtml = "<div>" +
       "<div data-bind='text: a'></div>" +
       "<div data-bind='if: b, css: { blue: a, white: a + b }'>" +
       "Something</div>" +
       "<ul data-bind='foreach: c'><li data-bind='text: $data'></li></ul>" +
       "<span data-bind='text: d()[0]()'></span>" +
      "</div>";
   
   
};
</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
Knockout
protoref = $(protohtml);
ko.bindingProvider.instance = original_binder;
ko.applyBindings(context, protoref.get(0));
 
pending…
KSB
protoref = $(protohtml);
ko.bindingProvider.instance = ksb_binder;
ko.applyBindings(context, protoref.get(0));
 
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