From 838d554ea3c0f9737fc8c2074680b4da79f7377e Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Wed, 6 Apr 2016 09:08:57 -0500 Subject: [PATCH] Add Timing Processes as a javascript til --- README.md | 1 + javascript/timing-processes.md | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 javascript/timing-processes.md diff --git a/README.md b/README.md index d3dfe4c..00b7493 100644 --- a/README.md +++ b/README.md @@ -146,6 +146,7 @@ _386 TILs and counting..._ - [Running ES6 Specs With Mocha](javascript/running-es6-specs-with-mocha.md) - [Splat Arguments To A Function](javascript/splat-arguments-to-a-function.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) - [Truthiness of Integer Arrays](javascript/truthiness-of-integer-arrays.md) diff --git a/javascript/timing-processes.md b/javascript/timing-processes.md new file mode 100644 index 0000000..0f153eb --- /dev/null +++ b/javascript/timing-processes.md @@ -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.