Detecting an “invalid date”

JavaScript performance comparison

Test case created by zVictor

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var valid = new Date();
  var invalid = new Date('invalid');

};
</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
comparison
// An invalid date object returns NaN for getTime() and NaN is the only
// object not strictly equal to itself.
valid.getTime() === valid.getTime();
invalid.getTime() === invalid.getTime()
pending…
timestamp isNaN
!isNaN(valid.getTime());
!isNaN(invalid.getTime());
pending…
isFinite
isFinite(valid);
isFinite(invalid);
pending…
comparison 2
// An invalid date object returns NaN for getTime() and NaN is the only
// object not strictly equal to itself.
var validTime = valid.getTime();
validTime === validTime;
var invalidTime = invalid.getTime();
invalidTime === invalidTime;
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