如何使用process.hrtime获取asynchronous函数的执行时间

我正在试图获得asynchronous函数的执行时间。 看来我可以使用process.hrtime这个。 我创build了简单的例子

console.log("starting"); var start = process.hrtime(); console.log("start"); console.log(start); setTimeout(function(){ console.log("HELLO"); var end = process.hrtime(); console.log("end"); console.log(end); }, 1000); 

它输出

 starting start [ 131806, 731009597 ] HELLO end [ 131807, 738212296 ] 

但是我不明白在几毫秒内exectuion的时间在哪里? 我希望在这个例子中获得1000毫秒。

得到它了:

 console.log("starting"); var start = process.hrtime(); console.log("start"); console.log(start); setTimeout(function(){ console.log("HELLO"); var end = process.hrtime(start); console.log("end"); console.log(end); }, 1000); 

打印

 starting start [ 132798, 207101051 ] HELLO end [ 1, 7001730 ] 

这意味着从开始到结束1秒和7001730纳秒