Calculate and log time elapsed in javascript