ECharts makeInner test

JavaScript performance comparison

Test case created by pissang

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  window.innerUniqueIndex = window.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] = {});
      };
  }
  // Simple key without random and special character
  function makeInnerSimpleKey() {
      // Consider different scope by es module import.
      var key = '__ec_inner_' + innerUniqueIndex++;
  
      return function (hostObj) {
          return hostObj[key] || (hostObj[key] = {});
      };
  }
  
  function makeInnerFixedKey() {
      // Consider different scope by es module import.
      var key = '__ec_inner_';
      return function (hostObj) {
          return hostObj[key] || (hostObj[key] = {});
      };
  }
  
  function makeInnerFixedKeyDefineProperty() {
      // Consider different scope by es module import.
      var key = '__ec_inner_';
      return function (hostObj) {
          if (!hostObj[key]) {
              Object.defineProperty(hostObj, key, {
                 enumerable: false,
                 value: {}
              });
          }
          return hostObj[key];
      };
  }
  
  const inner = makeInner();
  const innerSimple = makeInnerSimpleKey();
  const innerFixed = makeInnerFixedKey();
  const innerDefineProperty = makeInnerFixedKeyDefineProperty();
  
  const obj = {
     dataIndex: 2
  }
  const obj2 = {
     nest: {
        dataIndex: 2
     }
  };
  const obj3 = {}
  inner(obj3).dataIndex = 2;
  const obj4 = {}
  innerSimple(obj4).dataIndex = 2;
  const obj5 = {}
  innerFixed(obj5).dataIndex = 2;
  
  const obj6 = {}
  innerDefineProperty(obj6).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
Not nest
var a = obj.dataIndex;
pending…
Nest
var a = obj2.nest.dataIndex;
pending…
inner
var a = inner(obj3).dataIndex
pending…
inner with simple key
var a = innerSimple(obj4).dataIndex
pending…
inner with fixed key
var a = innerFixed(obj5).dataIndex
pending…
inner with fixed key and defineProperty
var a = innerDefineProperty(obj6).dataIndex
pending…

Revisions

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

0 Comments