aboutsummaryrefslogtreecommitdiff
path: root/node_modules/nanotiming/example.js
blob: 35b034ca4f685f13707ded9575299fd7f198d3cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
var nanotiming = require('./')

try {
  var hooks = require('perf_hooks')
  var nanot = nanotiming('my-loop') // Start profiling
} catch (e) {
  console.log('perf_hooks not available, exiting')
  process.exit(1)
}
var performance = hooks.performance

var i = 10
while (--i) console.log(i)

// Stop profiling
nanot()

var timings = performance.getEntries()
var timing = timings[timings.length - 1]
console.log(timing.name, timing.duration) // log the last entry
performance.clearMeasures(timing.name)    // be a good citizen and free after use