nodejs高精度计时(纳秒)

process.hrtime()
process.hrtime.bigint()

返回Array包含当前高分辨率实时的元组,在[秒,纳秒]

function getNanoSecTime() {
    var hrTime = process.hrtime();
    return hrTime[0] * 1000000000 + hrTime[1];
}

node v10.7.0以上

const start = process.hrtime.bigint();
// 191051479007711n

setTimeout(() => {
  const end = process.hrtime.bigint();
  // 191052633396993n

  console.log(`Benchmark took ${end - start} nanoseconds`);
  // Benchmark took 1154389282 nanoseconds
}, 1000);

https://nodejs.org/api/process.html#process_process_hrtime_time

你可能感兴趣的:(nodejs高精度计时(纳秒))