Load JSON into Existing Object (v2)

Revision 2 of this benchmark created by pcowdogg on


Description

Tests on how to load json object into existing object

Preparation HTML

<script>
  A = function(){
  //ref to self
  Object.defineProperty(this, "self", 
                       {value : null,
                        writable : true,
                        enumerable : false,
                        configurable : true});
  this.self=this;
  
  this.Astring = "This is a string"
  this.Anumber = 42
  
  
  this.overwriteData=function(data){
  for(prop in data){
        self[prop]=data[prop]
        }
     }
  this.redirrectData=function(data){
  for(prop in data){
        self[prop]=function(){
              self[prop]
           }
        }
     }
  }
  
  dataOBJ = JSON.parse(JSON.stringify(new A()))
  
  Test1 = new A() //control
  Test2 = new A() //overwrite Data
  Test2.overwriteData(dataOBJ)
  Test3 = new A() //redirrect Data
  Test3.redirrectData(dataOBJ)
  
  dataOBJ = null;
  
  
  
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Native Scope Reading
Test1.Astring
Test1.Anumber
ready
Replaced Vars
Test2.Astring
Test2.Anumber
ready
Redirected using functions
Test3.Astring
Test3.Anumber
ready
Population-Overwrite
Test2.overwriteData(dataOBJ)
ready
Population-Redirect
  Test3.redirrectData(dataOBJ)
ready

Revisions

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

  • Revision 1: published by pcowdogg on
  • Revision 2: published by pcowdogg on
  • Revision 4: published by pcowdogg on