jsIsNullTest

JavaScript performance comparison

Test case created by Brandon Boone

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function person() {}
  
  person.prototype.contact = {
    address: {
      city: {
        population: {
          medianAge: 36
        }
      }
    }
  };
  
  person.prototype.isNull = function(exp) {
    var i = 0,
      items = exp.split('.'),
      len = items.length,
      obj = this;
  
    for (i; i < len; i++) {
      if (!(obj = obj[items[i]]))
        return false;
    }
    return true;
  };
  
  var pInstance = new person();

};
</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
Explicit
if (pInstance &&
  pInstance.contact &&
  pInstance.contact.address &&
  pInstance.contact.address.city &&
  pInstance.contact.address.city.population &&
  pInstance.contact.address.city.population.medianAge) {
  return true;
}
pending…
Dynamic
if (pInstance.isNull('contact.address.city.population.medianAge')) {
  return true;
}
pending…
Escalation
var c;
if ((c = pInstance) &&
  (c = c.contact) &&
  (c = c.address) &&
  (c = c.city) &&
  (c = c.population) &&
  (c = c.medianAge)) {
  return true;
}
pending…

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

Compare results of other browsers

0 Comments