Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36
Chrome 114
Windows
Desktop
one year ago
Test name Executions per second
test1 583.8 Ops/sec
test2 577.8 Ops/sec
Script Preparation code:
x
 
var if1 = true;
var if2 = true;
var if3 = false;
function a() {
  var b = {};
  
  if (if1) {
    b.a = document.createElement("a");
  }
  if (if2) {
    b.b = document.createElement("a");
  }
  if (if3) {
    b.c = document.createElement("a");
  }
  return b;
}
function c() {
  var d = [];
  
  if (if1) {
    d.push(document.createElement("a"));
  }
  if (if2) {
    d.push(document.createElement("a"));
  }
  if (if3) {
    d.push(document.createElement("a"));
  }
  return d;
}
Tests:
  • test1

     
    for (let i = 0; i < 1000; ++i) {
      a();
    }
  • test2

     
    for (let i = 0; i < 1000; ++i) {
      c();
    }