mongo/jstests/noPassthrough/shell/js/std_performance.js
Matt Broadstone 41b16e48d9 SERVER-126888: Add a high-resolution timer for perf testing in jstests (#53877)
Co-authored-by: Steve McClure <steve.mcclure@mongodb.com>
Co-authored-by: Teo Voinea <teo.voinea@mongodb.com>
GitOrigin-RevId: e91b166957c79f6576efe2c6fbf6d796a9636905
2026-05-20 18:14:42 +00:00

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");
});
});