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:
25
javascript/timing-processes.md
Normal file
25
javascript/timing-processes.md
Normal 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.
|
||||
Reference in New Issue
Block a user