ko.viewmodel vs ko.mapping - viewmodel creation

JavaScript performance comparison

Test case created by CodeRenaissance

Preparation code

<script src="http://cdnjs.cloudflare.com/ajax/libs/knockout/2.2.0/knockout-min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/knockout.mapping/2.3.3/knockout.mapping.js"></script>
<script src="http://coderenaissance.github.com/knockout.viewmodel/knockout.viewmodel.min.js"></script>
      
<script>
Benchmark.prototype.setup = function() {
  var numberOfArrayRecords = 100,
  viewmodel = null,
  model = {
      items:[]
  };
  
  for(var x = 0; x < numberOfArrayRecords; x++){
      model.items.push({
          string:"Test",
          number:4,
          anotherObject:{
             items:[{id:4, name:"Test"},{id:7, name:"Test2"}] 
          }      
      });   
          
  }

};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
ko.mapping
viewmodel = ko.mapping.fromJS(model);
pending…
ko.viewmodel
viewmodel = ko.viewmodel.fromModel(model);
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.

4 Comments

Matthew Schinckel commented :

There seems to be an error with the ko.mapping version under Safari.

Karl commented :

When I ran the tests, I got:

Testing in Firefox 25.0 on OS X 10.7

TypeError: ko.viewmodel is undefined.

fileName: http://jsperf.com/ko-viewmodel-vs-ko-mapping-complex-viewmodel-creation

Karl commented :

Oooops...My bad! NoScript wasn't allowing all of the scripts. Works perfectly now.

4 commented :

5