ECharts makeInner test

JavaScript performance comparison

Revision 3 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.
      var key = '__ec_inner_';
      return function (hostObj) {
          return hostObj[key] || (hostObj[key] = {});
      };
  }
  
  
  function makeInnerSimpleKey2() {
      // Consider different scope by es module import.
      var key = '__ec_inner2_';
      return function (hostObj) {
          var o = hostObj[key];
          if (o !== undefined) {
              return o;
          }
          return (hostObj[key] = {});
      };
  }
  
  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
Nest
var a = obj2.nest.dataIndex;
pending…
inner
var a = inner(obj3).dataIndex
pending…
Not nest
var a = obj.dataIndex;
pending…
inner simple 2
var a = innerSimple2(obj5).dataIndex
pending…
inner with simple key
var a = innerSimple(obj4).dataIndex
pending…

Revisions

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

0 Comments