Return a high-resolution time difference.


var toc = require( '@stdlib/time/toc' );

toc( time )

Returns a high-resolution time difference, where time is a two-element array with format [seconds, nanoseconds].

var delta = toc( [ 100, 123456789 ] );
// returns [<number>,<number>]

Similar to time, the returned array has format [seconds, nanoseconds].


  • This function is intended to be used in conjunction with tic for measuring performance between intervals.


var tic = require( '@stdlib/time/tic' );
var toc = require( '@stdlib/time/toc' );

var start = tic();

setTimeout( onTimeout, 2000 );

function onTimeout() {
    var elapsed = toc( start );
    console.log( 'Elapsed: %d seconds and %d nanoseconds', elapsed[0], elapsed[1] );
Did you find this page helpful?