MEASURE PERFORMANCE IN JAVASCRIPT

Prasanna Brabourame
1 min readJan 30, 2020

The Performance interface provides access to performance-related information for the current page.

Performance.now()

Returns a DOMHighResTimeStamp;
//The time, given in milliseconds, should be accurate to 5 μs (microseconds), with the fractional part of the number indicating fractions of a millisecond.

Performance.mark()

Creates a timestamp in the browser’s performance entry buffer with the given name.

Syntax: performance.mark(name);

Performance.measure()

Creates a named timestamp in the browser’s performance entry buffer between two specified marks (known as the start mark and end mark, respectively).

Syntax: performance.measure(name, startMark, endMark);

Performance.clearMarks()

Removes the given mark from the browser’s performance entry buffer.

Performance.clearMeasures()

Removes the given measure from the browser’s performance entry buffer.

Performance.getEntries()

Returns a list of PerformanceEntry objects based on the given filter.

Performance.getEntriesByName()

Returns a list of PerformanceEntry objects based on the given name and entry type.

Performance.getEntriesByType()

The getEntriesByType() method returns a list of PerformanceEntry objects for a given type.

function measurePerformance() {
Performance.mark(‘FUNCTION_START’);
// Do Some Operation
Performance.mark(‘FUNCTION_END’); Performance.measure(‘FUNCTION_PERFROMANCE’, ‘FUNCTION_START’, ‘FUNCTION_END’);
console.log(Performance.getEntries()); console.log(Performance.getEntriesByName(‘ FUNCTION_PERFROMANCE’));
console.log(Performance.getEntriesByType(‘ measure’));
Performance.clearMarks();
Performance.clearMeasures();
}

--

--

Prasanna Brabourame

AI Engineer | Researcher | Open Source Enthusiast | Full Stack Dev | Blockchain | DEVOPS | Learner | Blogger | Speaker | Tech Geek