美文网首页
nodejs高精度计时(纳秒)

nodejs高精度计时(纳秒)

作者: droid_zf | 来源:发表于2019-05-29 16:49 被阅读0次
    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高精度计时(纳秒)

          本文链接:https://www.haomeiwen.com/subject/kxgytctx.html