overte/script-archive/libraries/usertimingExample.js

19 lines
649 B
JavaScript
Raw Permalink Normal View History

2015-11-06 16:19:49 -08:00
Script.include('usertiming.js');
var timing = loadUserTiming();
//set a mark
2015-11-06 22:05:30 -08:00
timing.performance.mark('firstMark');
2015-11-06 21:39:53 -08:00
//do something that takes time -- we're just going to set a timeout here as an example
2015-11-06 16:19:49 -08:00
Script.setTimeout(function() {
//and set another mark
2015-11-06 22:05:30 -08:00
timing.performance.mark('secondMark');
//measure time between marks (first parameter is a name for the measurement)
2015-11-06 21:39:53 -08:00
timing.performance.measure('howlong', 'firstMark', 'secondMark');
2015-11-06 22:05:30 -08:00
//you can also get the marks by changing the type
2015-11-06 21:39:53 -08:00
var measures = timing.performance.getEntriesByType('measure');
print('measures:::' + JSON.stringify(measures))
}, 1000)