node/deps/v8/test/js-perf-test/BigInt/as-int-n.js
Michaël Zasso 270253c4e2
deps: update V8 to 9.7.106.18
PR-URL: https://github.com/nodejs/node/pull/40907
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2022-01-20 10:38:37 +01:00

89 lines
1.9 KiB
JavaScript

// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
"use strict";
d8.file.execute('bigint-util.js');
let random_bigints = [];
// This dummy ensures that the feedback for benchmark.run() in the Measure
// function from base.js is not monomorphic, thereby preventing the benchmarks
// below from being inlined. This ensures consistent behavior and comparable
// results.
new BenchmarkSuite('Prevent-Inline-Dummy', [10000], [
new Benchmark('Prevent-Inline-Dummy', true, false, 0, () => {})
]);
[32, 64, 128, 256].forEach((d) => {
new BenchmarkSuite(`AsInt64-${d}`, [1000], [
new Benchmark(`AsInt64-${d}`, true, false, 0, TestAsInt64,
() => SetUpTestAsIntN(d))
]);
});
[32, 64, 128, 256].forEach((d) => {
new BenchmarkSuite(`AsInt32-${d}`, [1000], [
new Benchmark(`AsInt32-${d}`, true, false, 0, TestAsInt32,
() => SetUpTestAsIntN(d))
]);
});
[32, 64, 128, 256].forEach((d) => {
new BenchmarkSuite(`AsInt8-${d}`, [1000], [
new Benchmark(`AsInt8-${d}`, true, false, 0, TestAsInt8,
() => SetUpTestAsIntN(d))
]);
});
function SetUpTestAsIntN(d) {
random_bigints = [
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d)
];
}
function TestAsInt64() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
result = BigInt.asIntN(64, random_bigints[i % 8]);
}
return result;
}
function TestAsInt32() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
result = BigInt.asIntN(32, random_bigints[i % 8]);
}
return result;
}
function TestAsInt8() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
result = BigInt.asIntN(8, random_bigints[i % 8]);
}
return result;
}