1.

How to measure the performance of async operations?

Answer»

Performance API provides us with tools to FIGURE out the necessary performance metrics. 

A simple EXAMPLE would be:

CONST { PerformanceObserver, performance } = require('perf_hooks');const obs = new PerformanceObserver((items) => { console.log(items.getEntries()[0].DURATION); performance.clearMarks();});obs.observe({ entryTypes: ['measure'] });performance.measure('Start to Now');performance.mark('A');doSomeLongRunningProcess(() => { performance.measure('A to Now', 'A'); performance.mark('B'); performance.measure('A to B', 'A', 'B');});


Discussion

No Comment Found