1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-07 00:58:02 +00:00

Add Timing Processes as a javascript til

This commit is contained in:
jbranchaud
2016-04-06 09:08:57 -05:00
parent d9325bfa82
commit 838d554ea3
2 changed files with 26 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
# Timing Processes
If you want to time a process, you can use the `console.time()` and
`console.timeEnd()` utilities specified by the `console` Web API. Invoking
`console.time()` with a label starts a named timer. You can then run the
process you want to time. Then invoke `console.timeEnd()` with the same
label to terminate the timer and see how long the process took.
```javascript
console.time('sorting');
[11,10,9,8,7,6,5,4,3,2,1].sort();
console.timeEnd('sorting');
> sorting: 0.278ms
console.time('console logging');
console.log('logging to the console');
console.timeEnd('console logging');
> logging to the console
> console logging: 0.311ms
console.time('adding'); 1 + 1; console.timeEnd('adding');
> adding: 0.006ms
```
These functions are implemented in most modern browsers.