ECharts makeInner test2 (v12)

Revision 12 of this benchmark created by sushuang on


Setup

var innerUniqueIndex = 0;
  
  function makeInner() {
      // Consider different scope by es module import.
      var key = '__\0ec_inner_' + innerUniqueIndex++ + '_' + Math.random().toFixed(5);
      return function (hostObj) {
          return hostObj[key] || (hostObj[key] = {});
      };
  }
  
  function makeInnerSimpleKey() {
      // Consider different scope by es module import.
      return function (hostObj) {
          return hostObj.nest || (hostObj.nest = {});
      };
  }
  
  
  function makeInnerSimpleKey2() {
      // Consider different scope by es module import.
      return function (hostObj) {
          var o = hostObj.nest;
          if (o !== undefined) {
              return o;
          }
          return (hostObj.nest = {});
      };
  }
  
  const inner = makeInner();
  const innerSimple = makeInnerSimpleKey();
  const innerSimple2 = makeInnerSimpleKey2();
  
  const obj = {
     dataIndex: 2
  }
  const obj2 = {
     nest: {
        dataIndex: 2
     }
  };
  const obj3 = {}
  // inner(obj3).dataIndex = 2;
  const obj4 = {}
  // innerSimple(obj4).dataIndex = 2;
  const obj5 = {}
  // innerSimple2(obj5).dataIndex = 2;
  var host = [];
  
  function save(obj) {
      if (host.length > 1000) {
          host = [];
      }
      host.push(obj);
  }

Teardown



            host = [];
        
  

Test runner

Ready to run.

Testing in
TestOps/sec
inner simple 2
var objj = {};
save(objj);
innerSimple2(objj).dataIndex = 3;
var a = 0;
for (var i = 0; i < 100; i++) {
    a += innerSimple2(objj).dataIndex
}
ready
inner simple 2-1
var objj = {};
save(objj);
if (objj.nest === undefined) {
    objj.nest = {};
}
objj.nest.dataIndex = 3;
var a = 0;
for (var i = 0; i < 100; i++) {
    if (objj.nest !== undefined) {
        a += objj.nest.dataIndex;
    }
}
ready
Not nest
var objj = {};
save(objj);
objj.dataIndex = 3;
var a = 0;
for (var i = 0; i < 100; i++) {
    a += objj.dataIndex;
}
ready
Nest
var objj = {};
save(objj);
objj.nest = {};
objj.nest.dataIndex = 3;
var a = 0;
for (var i = 0; i < 100; i++) {
    a += objj.nest.dataIndex;
}
ready
inner
var objj = {};
save(objj);
inner(objj).dataIndex = 3;
var a = 0;
for (var i = 0; i < 100; i++) {
    a += inner(objj).dataIndex
}
ready
inner with simple key
var objj = {};
save(objj);
innerSimple(objj).dataIndex = 3;
var a = 0;
for (var i = 0; i < 100; i++) {
    a += innerSimple(objj).dataIndex;
}
ready
inner simple 2-2
var objj = {};
save(objj);
objj.nest = {};
objj.nest.dataIndex = 3;
var a = 0;
for (var i = 0; i < 100; i++) {
    a += objj.nest.dataIndex;
}
ready

Revisions

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