當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Node.js process.hrtime.bigint()用法及代碼示例


process.hrtime.bigint()

添加於:v10.7.0

process.hrtime() 方法的 bigint 版本以 bigint 的形式返回當前的 high-resolution 實時(以納秒為單位)。

process.hrtime() 不同,它不支持額外的 time 參數,因為可以直接通過減去兩個 bigint 來計算差異。

import { hrtime } from 'node:process';

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

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

  console.log(`Benchmark took ${end - start} nanoseconds`);
  // Benchmark took 1154389282 nanoseconds
}, 1000);const { hrtime } = require('node:process');

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

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

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

相關用法


注:本文由純淨天空篩選整理自nodejs.org大神的英文原創作品 process.hrtime.bigint()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。