2019-12-06 07:39:16 +08:00
|
|
|
'use strict';
|
2023-02-18 18:18:04 +08:00
|
|
|
|
|
|
|
if (typeof SharedArrayBuffer === 'undefined') {
|
|
|
|
throw new Error('SharedArrayBuffers must be enabled to run this benchmark');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof Atomics === 'undefined') {
|
|
|
|
throw new Error('Atomics must be enabled to run this benchmark');
|
|
|
|
}
|
2019-12-06 07:39:16 +08:00
|
|
|
|
|
|
|
const common = require('../common.js');
|
|
|
|
const bench = common.createBenchmark(main, {
|
2023-01-30 02:13:35 +08:00
|
|
|
n: [1e7],
|
2019-12-06 07:39:16 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
function main({ n }) {
|
|
|
|
const i32arr = new Int32Array(new SharedArrayBuffer(4));
|
|
|
|
bench.start();
|
|
|
|
for (let i = 0; i < n; i++)
|
|
|
|
Atomics.wait(i32arr, 0, 1); // Will return immediately.
|
|
|
|
bench.end(n);
|
|
|
|
}
|