Co-authored-by: Steve McClure <steve.mcclure@mongodb.com> Co-authored-by: Teo Voinea <teo.voinea@mongodb.com> GitOrigin-RevId: e91b166957c79f6576efe2c6fbf6d796a9636905
23 lines
848 B
JavaScript
23 lines
848 B
JavaScript
import {describe, it} from "jstests/libs/mochalite.js";
|
|
import {performance} from "std:performance";
|
|
|
|
describe("std:performance with performance internal binding", function () {
|
|
it("uses a monotonic high-resolution clock", function () {
|
|
const first = performance.now();
|
|
const second = performance.now();
|
|
|
|
assert.gte(first, 0, "performance.now() should be non-negative");
|
|
assert.gte(second, first, "performance.now() should be monotonic");
|
|
|
|
let sawFractionalValue = false;
|
|
for (let i = 0; i < 20000; ++i) {
|
|
const sample = performance.now();
|
|
if (!Number.isInteger(sample)) {
|
|
sawFractionalValue = true;
|
|
break;
|
|
}
|
|
}
|
|
assert(sawFractionalValue, "performance.now() should report sub-millisecond precision");
|
|
});
|
|
});
|