596 B
596 B
title, type, language, tags, cover, dateModified
| title | type | language | tags | cover | dateModified | |
|---|---|---|---|---|---|---|
| Time taken by function | snippet | javascript |
|
shelf-plant | 2020-10-22T20:24:30+03:00 |
Measures the time it takes for a function to execute.
- Use
console.time()andconsole.timeEnd()to measure the difference between the start and end times to determine how long the callback took to execute.
const timeTaken = callback => {
console.time('timeTaken');
const r = callback();
console.timeEnd('timeTaken');
return r;
};
timeTaken(() => Math.pow(2, 10)); // 1024, (logged): timeTaken: 0.02099609375ms