optional chaining empty object

JavaScript performance comparison

Test case created by erykpiast

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const foo={};
  function dlv(n,t,o,i,l){for(t=t.split?t.split("."):t,i=0;i<t.length;i++)n=n?n[t[i]]:l;return n===l?o:n}

};
</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
old spice
foo && foo.bar && foo.bar.baz && foo.bar.baz.qux
pending…
dlv (string)
dlv(foo, "bar.baz.qux");
pending…
dlv (array)
dlv(foo, ['bar', 'baz', 'qux']);
pending…
optional chaining (TypeScript)
var o,l,v;null===(v=null===(l=null===(o=foo)||void 0===o?void 0:o.bar)||void 0===l?void 0:l.baz)||void 0===v||v.qux
pending…
optional chaining (Babel)
var l,n;null==foo||null===(l=foo.bar)||void 0===l||null===(n=l.baz)||void 0===n||n.qux
pending…
optional chaining (native)
foo?.bar?.baz?.qux;
pending…

Compare results of other browsers

Revisions

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

0 Comments