v8/test/js-perf-test/BigInt/as-int-n.js
Nico Hartmann 3f31ffd019 BigInt.asIntN benchmark
Bug: v8:9407
Change-Id: Icc3130a028003f146e733b13b05568b434b530fe
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3218153
Auto-Submit: Nico Hartmann <nicohartmann@chromium.org>
Reviewed-by: Maya Lekova <mslekova@chromium.org>
Commit-Queue: Maya Lekova <mslekova@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77344}
2021-10-12 12:14:39 +00: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;
}