Timers
Timers
Mocha test have a built-in benchmarking tool for each unit tested. When Mocha is not used or a specific test is needed, the process.hrtime() can be used.
process.hrtime() is called each time a timer needs to be started and stopped. When the time between two events is required, the starting value is passed as a parameter.
const pw = require('playwright');
const assert = require('assert');
(async () => {
const browser = await pw.chromium.launch();
const context = await browser.newContext();
const page = await context.newPage();
let start = process.hrtime();
await page.goto('http://leafground.com/');
let title = await page.title();
try {
await assert.strictEqual(title, 'TestLeaf - Selenium Playground', 'Title match!');
}
catch (e) {
console.log(e);
}
let end = process.hrtime(start); // time between start and here
let start2 = process.hrtime();
await page.close();
await context.close();
await browser.close();
let end2 = process.hrtime(start2); // time between start2 and here
console.log('Time 1: ' + end);
console.log('Time 2: ' + end2);
})();