Created
January 16, 2015 07:44
-
-
Save greenlikeorange/4af01dfc77d7472efae4 to your computer and use it in GitHub Desktop.
Process Time (nodejs)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function constr(){ | |
return new ProcessTime(); | |
} | |
function ProcessTime(){ | |
this._start_time = new Date(); | |
} | |
ProcessTime.prototype.done = function(format, nonPrint){ | |
var differ = ((new Date()) - this._start_time); | |
var mms = differ%1000 !== 0 ? ( (differ/1000) +"").split(".")[1] : "0000"; | |
var floor = Math.floor(differ/1000); | |
var h, m, s; | |
var res; | |
switch(format){ | |
case "s": | |
res = floor + "." + mms; | |
break; | |
default: | |
h = Math.floor(floor/3600); | |
h = h < 10 ? "0"+h : h; | |
m = Math.floor(floor%3600/60); | |
m = m < 10 ? "0"+m : m; | |
s = floor%60; | |
s = s < 10 ? "0"+s : s; | |
res = h+"."+m+"."+s+"."+mms; | |
break; | |
} | |
if(!nonPrint) | |
console.log("Process Escape Time: " + res); | |
return res; | |
} | |
module.exports = constr; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage