Birthday Calculation (v5)

Revision 5 of this benchmark created on


Setup

var dateString = "1992-01-13";
  var dateString2 = "01-13-1992";

Test runner

Ready to run.

Testing in
TestOps/sec
Accepted Answer
var ms = new Date() - new Date(dateString); 
return ms; 
ready
Optimized code
calcAge(dateString);

function calcAge(dateString) {
  var birthday = +new Date(dateString);
  return ~~((Date.now() - birthday) / (31557600000));
}
ready

Revisions

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