mirror of
https://github.com/jbranchaud/til
synced 2026-01-05 16:18:01 +00:00
Add Timing Processes as a javascript til
This commit is contained in:
@@ -146,6 +146,7 @@ _386 TILs and counting..._
|
|||||||
- [Running ES6 Specs With Mocha](javascript/running-es6-specs-with-mocha.md)
|
- [Running ES6 Specs With Mocha](javascript/running-es6-specs-with-mocha.md)
|
||||||
- [Splat Arguments To A Function](javascript/splat-arguments-to-a-function.md)
|
- [Splat Arguments To A Function](javascript/splat-arguments-to-a-function.md)
|
||||||
- [Throttling A Function Call](javascript/throttling-a-function-call.md)
|
- [Throttling A Function Call](javascript/throttling-a-function-call.md)
|
||||||
|
- [Timing Processes](javascript/timing-processes.md)
|
||||||
- [Transforming ES6 and JSX With Babel 6](javascript/transforming-es6-and-jsx-with-babel-6.md)
|
- [Transforming ES6 and JSX With Babel 6](javascript/transforming-es6-and-jsx-with-babel-6.md)
|
||||||
- [Truthiness of Integer Arrays](javascript/truthiness-of-integer-arrays.md)
|
- [Truthiness of Integer Arrays](javascript/truthiness-of-integer-arrays.md)
|
||||||
|
|
||||||
|
|||||||
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