11cb0ef41Sopenharmony_cifunction testTimeResolution(highResTimeFunc, funcString) {
21cb0ef41Sopenharmony_ci    test(() => {
31cb0ef41Sopenharmony_ci        const t0 = highResTimeFunc();
41cb0ef41Sopenharmony_ci        let t1 = highResTimeFunc();
51cb0ef41Sopenharmony_ci        while (t0 == t1) {
61cb0ef41Sopenharmony_ci            t1 = highResTimeFunc();
71cb0ef41Sopenharmony_ci        }
81cb0ef41Sopenharmony_ci        const epsilon = 1e-5;
91cb0ef41Sopenharmony_ci        assert_greater_than_equal(t1 - t0, 0.005 - epsilon, 'The second ' + funcString + ' should be much greater than the first');
101cb0ef41Sopenharmony_ci    }, 'Verifies the resolution of ' + funcString + ' is at least 5 microseconds.');
111cb0ef41Sopenharmony_ci}
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_cifunction timeByPerformanceNow() {
141cb0ef41Sopenharmony_ci    return performance.now();
151cb0ef41Sopenharmony_ci}
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_cifunction timeByUserTiming() {
181cb0ef41Sopenharmony_ci    performance.mark('timer');
191cb0ef41Sopenharmony_ci    const time = performance.getEntriesByName('timer')[0].startTime;
201cb0ef41Sopenharmony_ci    performance.clearMarks('timer');
211cb0ef41Sopenharmony_ci    return time;
221cb0ef41Sopenharmony_ci}
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_citestTimeResolution(timeByPerformanceNow, 'performance.now()');
251cb0ef41Sopenharmony_citestTimeResolution(timeByUserTiming, 'entry.startTime');
26