time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

README.md (1812B)


      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 # toc
     22 
     23 > Return a high-resolution time difference.
     24 
     25 <section class="usage">
     26 
     27 ## Usage
     28 
     29 ```javascript
     30 var toc = require( '@stdlib/time/toc' );
     31 ```
     32 
     33 #### toc( time )
     34 
     35 Returns a high-resolution time difference, where `time` is a two-element `array` with format `[seconds, nanoseconds]`.
     36 
     37 ```javascript
     38 var delta = toc( [ 100, 123456789 ] );
     39 // returns [<number>,<number>]
     40 ```
     41 
     42 Similar to `time`, the returned `array` has format `[seconds, nanoseconds]`.
     43 
     44 </section>
     45 
     46 <!-- /.usage -->
     47 
     48 <secton class="notes">
     49 
     50 ## Notes
     51 
     52 -   This function is intended to be used in conjunction with [`tic`][@stdlib/time/tic] for measuring performance between intervals.
     53 
     54 </section>
     55 
     56 <!-- /.notes -->
     57 
     58 <section class="examples">
     59 
     60 ## Examples
     61 
     62 <!-- eslint no-undef: "error" -->
     63 
     64 ```javascript
     65 var tic = require( '@stdlib/time/tic' );
     66 var toc = require( '@stdlib/time/toc' );
     67 
     68 var start = tic();
     69 
     70 setTimeout( onTimeout, 2000 );
     71 
     72 function onTimeout() {
     73     var elapsed = toc( start );
     74     console.log( 'Elapsed: %d seconds and %d nanoseconds', elapsed[0], elapsed[1] );
     75 }
     76 ```
     77 
     78 </section>
     79 
     80 <!-- /.examples -->
     81 
     82 <section class="links">
     83 
     84 [@stdlib/time/tic]: https://www.npmjs.com/package/@stdlib/time/tree/main/tic
     85 
     86 </section>
     87 
     88 <!-- /.links -->