What is the best way to measure time and memory of execution JS function?

#1

Hi, I write some solutions based on task, where I have to remove duplicates from an array.
I want to measure time and memory of execution functions above - just for studying. Probably, I will write some post for gain employment. I have read about console.time(), new Date(), performance.now() “The timestamp is not actually high-resolution.”. What do you recommend?

Sample array: Array: [11, 22, 11, 33, "Martin", "Mark", "John", false, false, "John"]
Sample function 1: const solve = (arr) => [...new Set(arr)]
Sample function 2:
const solve = arr => { let non_duplicates = [] return arr.reduce((acc, cur) => { if (non_duplicates.indexOf(cur) === -1) { non_duplicates.push(cur); } return non_duplicates; }); };
Solution: [11, 22, 33, "Martin", "Mark", "John", false]

#2

I recommend that you use the performance tab that comes with most browser dev tools.

3 Likes
#4

I have checked the tab performance in Chrome Dev Tools.
I wanted to check execution of the following function:

 const solve = arr => arr.filter((non_duplicates, next) => arr.indexOf(non_duplicates) === next );

Should I use the reload icon and take the result from “Scripting” like on the picture below - http://prntscr.com/nou8at?

#5

The Bottom-Up and Call Tree tabs are where you can dig in to further details.
It can also help to zoom in to the timeline and click on the function of interest.