README.md (2053B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2018 The Stdlib Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 --> 20 21 # tic 22 23 > Return a high-resolution time. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var tic = require( '@stdlib/time/tic' ); 31 ``` 32 33 #### tic() 34 35 Returns a high-resolution time. 36 37 ```javascript 38 var t = tic(); 39 // returns [<number>,<number>] 40 ``` 41 42 The returned `array` has the following format: `[seconds, nanoseconds]`. 43 44 </section> 45 46 <!-- /.usage --> 47 48 <secton class="notes"> 49 50 ## Notes 51 52 - In browser environments, the implementation uses the [`performance.now`][performance-now] API. If the [`performance-now`][performance-now] API is unavailable, the implementation falls back to the [`Date`][date] object. 53 - In non-browser environments, the implementation uses [`process.hrtime`][process-hrtime]. 54 55 </section> 56 57 <!-- /.notes --> 58 59 <section class="examples"> 60 61 ## Examples 62 63 <!-- eslint no-undef: "error" --> 64 65 ```javascript 66 var tic = require( '@stdlib/time/tic' ); 67 var toc = require( '@stdlib/time/toc' ); 68 69 var start = tic(); 70 71 setTimeout( onTimeout, 2000 ); 72 73 function onTimeout() { 74 var elapsed = toc( start ); 75 console.log( 'Elapsed: %d seconds and %d nanoseconds', elapsed[0], elapsed[1] ); 76 } 77 ``` 78 79 </section> 80 81 <!-- /.examples --> 82 83 <section class="links"> 84 85 [performance-now]: https://developer.mozilla.org/en-US/docs/Web/API/Performance/now 86 87 [date]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now 88 89 [process-hrtime]: https://nodejs.org/api/process.html#process_process_hrtime_time 90 91 </section> 92 93 <!-- /.links -->