当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


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()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。