knockout observable vs peek (v7)

Revision 7 of this benchmark created on


Preparation HTML

<script src="http://knockoutjs.com/downloads/knockout-3.4.0rc.js"></script>

<!-- This is a *view* - HTML markup that defines the appearance of your UI -->
<div id="wrapper">
<p>First name: <input data-bind="value: firstName" /></p>
<p>Last name: <input data-bind="value: lastName" /></p>
<p>Full name: <strong data-bind="text: fullName"></strong></p>
</div>

Setup

// This is a simple *viewmodel* - JavaScript that defines the data and behavior of your UI
        var wrapper = document.getElementById('wrapper');
    
        function AppViewModel() {
            this.firstName = ko.observable("Bert");
            this.lastName = ko.observable("Bertington");
            
            this.fullName = ko.computed(function() {
                return this.firstName() + " " + this.lastName();    
            }, this);
        }
    
        var app = new AppViewModel();
        
        // Activates knockout.js
        ko.applyBindings(app, wrapper);

Teardown


    var wrapper = document.getElementById('wrapper');
    ko.cleanNode(wrapper);
  

Test runner

Ready to run.

Testing in
TestOps/sec
Normal with subs
app.fullName();
ready
peek
app.fullName.peek();
ready

Revisions

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