ECharts makeInner test

JavaScript performance comparison

Revision 5 of this test case created by sushuang

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  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.__ec_inner_ || (hostObj.__ec_inner_ = {});
      };
  }
  
  
  function makeInnerSimpleKey2() {
      // Consider different scope by es module import.
      return function (hostObj) {
          var o = hostObj.__ec_inner2_;
          if (o !== undefined) {
              return o;
          }
          return (hostObj.__ec_inner2_ = {});
      };
  }
  
  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;

};
</script>

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
inner simple 2
var objj = {};
innerSimple2(objj).dataIndex = 3;
var a = 0;
for (var i = 0; i < 100; i++) {
    a += innerSimple2(objj).dataIndex
}
pending…
inner with simple key
var objj = {};
innerSimple(objj).dataIndex = 3;
var a = 0;
for (var i = 0; i < 100; i++) {
    a += innerSimple(objj).dataIndex;
}
pending…
inner
var objj = {};
inner(objj).dataIndex = 3;
var a = 0;
for (var i = 0; i < 100; i++) {
    a += inner(objj).dataIndex
}
pending…
Nest
var objj = {};
objj.nest = {};
objj.nest.dataIndex = 3;
var a = 0;
for (var i = 0; i < 100; i++) {
    a += objj.nest.dataIndex;
}
pending…
Not nest
var objj = {};
objj.dataIndex = 3;
var a = 0;
for (var i = 0; i < 100; i++) {
    a += objj.dataIndex;
}
pending…

Revisions

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

0 Comments