diff --git a/CHANGELOG.md b/CHANGELOG.md index 32d9c36021..90fbbd2d64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ See the [migration guide](./docs/migration.md) for details of how to migrate fro ### Added ### Changed +* Use performance timers for test case duration measurement. ### Deprecated diff --git a/features/usage_formatter.feature b/features/usage_formatter.feature index a53a2d9cd7..921f0fecab 100644 --- a/features/usage_formatter.feature +++ b/features/usage_formatter.feature @@ -33,21 +33,21 @@ Feature: usage formatter When I run cucumber-js with `--format usage` Then it outputs the text: """ - ┌────────────────────┬──────────┬───────────────────────────────────────┐ - │ Pattern / Text │ Duration │ Location │ - ├────────────────────┼──────────┼───────────────────────────────────────┤ - │ step A │ ms │ features/step_definitions/steps.js:3 │ - │ step A │ ms │ features/a.feature:3 │ - ├────────────────────┼──────────┼───────────────────────────────────────┤ - │ /^(slow )?step B$/ │ ms │ features/step_definitions/steps.js:4 │ - │ slow step B │ ms │ features/a.feature:5 │ - │ step B │ ms │ features/a.feature:4 │ - ├────────────────────┼──────────┼───────────────────────────────────────┤ - │ step C │ ms │ features/step_definitions/steps.js:11 │ - │ step C │ ms │ features/a.feature:6 │ - ├────────────────────┼──────────┼───────────────────────────────────────┤ - │ step D │ UNUSED │ features/step_definitions/steps.js:12 │ - └────────────────────┴──────────┴───────────────────────────────────────┘ + ┌────────────────────┬──────────────┬───────────────────────────────────────┐ + │ Pattern / Text │ Duration │ Location │ + ├────────────────────┼──────────────┼───────────────────────────────────────┤ + │ step A │ ms │ features/step_definitions/steps.js:3 │ + │ step A │ ms │ features/a.feature:3 │ + ├────────────────────┼──────────────┼───────────────────────────────────────┤ + │ /^(slow )?step B$/ │ ms │ features/step_definitions/steps.js:4 │ + │ slow step B │ ms │ features/a.feature:5 │ + │ step B │ ms │ features/a.feature:4 │ + ├────────────────────┼──────────────┼───────────────────────────────────────┤ + │ step C │ ms │ features/step_definitions/steps.js:11 │ + │ step C │ ms │ features/a.feature:6 │ + ├────────────────────┼──────────────┼───────────────────────────────────────┤ + │ step D │ UNUSED │ features/step_definitions/steps.js:12 │ + └────────────────────┴──────────────┴───────────────────────────────────────┘ """ Scenario: only list 5 slowest matches @@ -81,15 +81,15 @@ Feature: usage formatter When I run cucumber-js with `--format usage` Then it outputs the text: """ - ┌──────────────────┬──────────┬──────────────────────────────────────┐ - │ Pattern / Text │ Duration │ Location │ - ├──────────────────┼──────────┼──────────────────────────────────────┤ - │ /^(slow )?step$/ │ ms │ features/step_definitions/steps.js:3 │ - │ slow step │ ms │ features/a.feature:3 │ - │ slow step │ ms │ features/a.feature:3 │ - │ slow step │ ms │ features/a.feature:3 │ - │ slow step │ ms │ features/a.feature:3 │ - │ slow step │ ms │ features/a.feature:3 │ - │ 5 more │ │ │ - └──────────────────┴──────────┴──────────────────────────────────────┘ + ┌──────────────────┬──────────────┬──────────────────────────────────────┐ + │ Pattern / Text │ Duration │ Location │ + ├──────────────────┼──────────────┼──────────────────────────────────────┤ + │ /^(slow )?step$/ │ ms │ features/step_definitions/steps.js:3 │ + │ slow step │ ms │ features/a.feature:3 │ + │ slow step │ ms │ features/a.feature:3 │ + │ slow step │ ms │ features/a.feature:3 │ + │ slow step │ ms │ features/a.feature:3 │ + │ slow step │ ms │ features/a.feature:3 │ + │ 5 more │ │ │ + └──────────────────┴──────────────┴──────────────────────────────────────┘ """ diff --git a/src/time.ts b/src/time.ts index ab3d50cda6..32ec1c9ed3 100644 --- a/src/time.ts +++ b/src/time.ts @@ -1,3 +1,4 @@ +import { performance } from 'perf_hooks' import * as messages from '@cucumber/messages' let previousTimestamp: number @@ -14,6 +15,7 @@ const methods: any = { }, setInterval: setInterval.bind(global), setTimeout: setTimeout.bind(global), + performance, } if (typeof setImmediate !== 'undefined') { @@ -22,7 +24,7 @@ if (typeof setImmediate !== 'undefined') { } function getTimestamp(): number { - return new methods.Date().getTime() + return methods.performance.now() } export function durationBetweenTimestamps(