[js-perf-test] Clean up BigInt perf tests

This CL removes

- redundant perf tests for addition and subtraction
- deprecated perf tests of addition without optimization
- perf tests for error throwing

Bug: v8:9407
Change-Id: Ib6c6015e1547ed87de071c430661cb2ad084c9ca
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4151201
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Reviewed-by: Nico Hartmann <nicohartmann@chromium.org>
Commit-Queue: Qifan Pan <panq@google.com>
Cr-Commit-Position: refs/heads/main@{#85187}
This commit is contained in:
Qifan Pan 2023-01-10 14:35:52 +01:00 committed by V8 LUCI CQ
parent 22ec1bc787
commit 5cf5e8184b
7 changed files with 1 additions and 271 deletions

View File

@ -1,75 +0,0 @@
// Copyright 2022 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, () => {})
]);
new BenchmarkSuite(`Add-Small`, [1000], [
new Benchmark(`Add-Small`, true, false, 0, TestAdd,
() => SetUpRandomBigInts(32))
]);
new BenchmarkSuite(`Add-Large`, [1000], [
new Benchmark(`Add-Large`, true, false, 0, TestAdd,
() => SetUpRandomBigInts(8192))
]);
new BenchmarkSuite(`Add-LargerThanSmall`, [1000], [
new Benchmark(`Add-LargerThanSmall`, true, false, 0, TestAdd,
() => SetUpRandomBigInts(68))
]);
new BenchmarkSuite(`Add-Random`, [1000], [
new Benchmark(`Add-Random`, true, false, 0, TestAdd,
SetUpTestAddRandom)
]);
function SetUpRandomBigInts(bits) {
random_bigints = [];
// RandomBigIntWithBits needs multiples of 4 bits.
bits = Math.floor(bits / 4) * 4;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
const bigint = RandomBigIntWithBits(bits);
random_bigints.push(Math.random() < 0.5 ? -bigint : bigint);
}
}
function SetUpTestAddRandom() {
random_bigints = [];
// RandomBigIntWithBits needs multiples of 4 bits.
const max_in_4bits = RANDOM_BIGINTS_MAX_BITS / 4;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
const bits = Math.floor(Math.random() * max_in_4bits) * 4;
const bigint = RandomBigIntWithBits(bits);
random_bigints.push(Math.random() < 0.5 ? -bigint : bigint);
}
}
function TestAdd() {
let sum = 0n;
for (let i = 0; i < TEST_ITERATIONS - 1; ++i) {
sum += random_bigints[i] + random_bigints[i + 1];
}
return sum;
}

View File

@ -19,12 +19,6 @@ new BenchmarkSuite('Prevent-Inline-Dummy', [10000], [
]);
new BenchmarkSuite('Add-TypeError', [10000], [
new Benchmark('Add-TypeError', true, false, 0, TestAddTypeError,
SetUpTestAddTypeError)
]);
new BenchmarkSuite('Add-Zero', [1000], [
new Benchmark('Add-Zero', true, false, 0, TestAddZero, SetUpTestAddZero)
]);
@ -52,24 +46,6 @@ new BenchmarkSuite('Add-Random', [1000], [
]);
function SetUpTestAddTypeError() {
initial_sum = 42n;
}
function TestAddTypeError() {
let sum = initial_sum;
for (let i = 0; i < SLOW_TEST_ITERATIONS; ++i) {
try {
sum = 0 + sum;
}
catch(e) {
}
}
return sum;
}
function SetUpTestAddZero() {
initial_sum = 42n;
}

View File

@ -7,10 +7,7 @@
// Test configuration.
const TEST_ITERATIONS = 1000;
const SLOW_TEST_ITERATIONS = 50;
const SMALL_BITS_CASES = [32, 64, 128, 256];
const MEDIUM_BITS_CASES = [512, 1024];
const BIG_BITS_CASES = [2048, 4096, 8192];
const BITS_CASES = [32, 64, 128, 256, 512, 1024, 2048, 4096, 8192];
const BITS_CASES = [32, 64, 1024, 8192];
const RANDOM_BIGINTS_MAX_BITS = 64 * 100;
const BIGINT_MAX_BITS = %BigIntMaxLengthBits();

View File

@ -1,48 +0,0 @@
// Copyright 2022 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_exponents = [];
// 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, () => {})
]);
new BenchmarkSuite('Exponentiate-Base-Two', [10000], [
new Benchmark('Exponentiate-Base-Two', true, false, 0,
TestExponentiateBaseTwo, SetUpTestExponentiateBaseTwo)
]);
function SetUpTestExponentiateBaseTwo() {
random_exponents = [];
// Restrict the maximum length of exponents to 20 bits so that the durations
// are reasonable and BigIntTooBig exceptions can be avoided.
const max_in_4bits = 20 / 4;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
const bits = Math.floor(Math.random() * max_in_4bits) * 4;
const bigint = RandomBigIntWithBits(bits);
// Exponents are non-negative.
random_exponents.push(bigint);
}
}
function TestExponentiateBaseTwo() {
let sum = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
sum += 2n ** random_exponents[i];
}
return sum;
}

View File

@ -18,16 +18,6 @@ new BenchmarkSuite('Prevent-Inline-Dummy', [100], [
new Benchmark('Prevent-Inline-Dummy', true, false, 0, () => {})
]);
new BenchmarkSuite('ShiftLeft-ShiftTooBig', [1000], [
new Benchmark('ShiftLeft-ShiftTooBig', true, false, 0,
TestShiftLeftShiftTooBig, SetUpTestShiftLeftShiftTooBig)
]);
new BenchmarkSuite('ShiftLeft-ResultTooBig', [1000], [
new Benchmark('ShiftLeft-ResultTooBig', true, false, 0,
TestShiftLeftResultTooBig, SetUpTestShiftLeftResultTooBig)
]);
new BenchmarkSuite('ShiftLeft-Small', [1000], [
new Benchmark('ShiftLeft-Small', true, false, 0,
TestShiftLeftSmall, SetUpTestShiftLeftSmall)
@ -81,43 +71,6 @@ function SetUpRandomBigInts() {
}
function SetUpTestShiftLeftShiftTooBig() {
// Left shifting by 2^80 is throwing an exception.
a = SmallRandomBigIntWithBits(80);
SetUpRandomBigInts();
}
function TestShiftLeftShiftTooBig() {
let result = 0n;
for (let i = 0; i < SLOW_TEST_ITERATIONS; ++i) {
try {
result = random_bigints[i] << a;
} catch(e) {
}
}
return result;
}
function SetUpTestShiftLeftResultTooBig() {
a = BigInt(BIGINT_MAX_BITS - 4);
for (let i = 0; i < SLOW_TEST_ITERATIONS; ++i) {
random_bigints[i] = RandomBigIntWithBits(64);
}
}
function TestShiftLeftResultTooBig() {
let result = 0n;
for (let i = 0; i < SLOW_TEST_ITERATIONS; ++i) {
try {
result = random_bigints[i] << a;
} catch(e) {
}
}
return result;
}
function SetUpTestShiftLeftSmall() {
random_bigints = [];
// Set up all values such that the left shifted values still fit into one

View File

@ -19,12 +19,6 @@ new BenchmarkSuite('Prevent-Inline-Dummy', [10000], [
]);
new BenchmarkSuite('Subtract-TypeError', [10000], [
new Benchmark('Subtract-TypeError', true, false, 0, TestSubtractTypeError,
SetUpTestSubtractTypeError)
]);
new BenchmarkSuite('Subtract-Zero', [1000], [
new Benchmark('Subtract-Zero', true, false, 0, TestSubtractZero,
SetUpTestSubtractZero)
@ -114,24 +108,6 @@ function TestSubtractRandom() {
}
function SetUpTestSubtractTypeError() {
initial_diff = 42n;
}
function TestSubtractTypeError() {
let diff = initial_diff;
for (let i = 0; i < SLOW_TEST_ITERATIONS; ++i) {
try {
diff = 0 - diff;
}
catch(e) {
}
}
return diff;
}
function SetUpTestSubtractZero() {
initial_diff = 42n;
}

View File

@ -73,8 +73,6 @@
"test_flags": ["shift"],
"results_regexp": "^BigInt\\-%s\\(Score\\): (.+)$",
"tests": [
{ "name": "ShiftLeft-ShiftTooBig" },
{ "name": "ShiftLeft-ResultTooBig" },
{ "name": "ShiftLeft-Small" },
{ "name": "ShiftLeft-Random" },
{ "name": "ShiftLeft-Growing" },
@ -105,43 +103,18 @@
"test_flags": ["add"],
"results_regexp": "^BigInt\\-%s\\(Score\\): (.+)$",
"tests": [
{ "name": "Add-TypeError" },
{ "name": "Add-Zero" },
{ "name": "Add-SameSign-32" },
{ "name": "Add-DifferentSign-32" },
{ "name": "Add-SameSign-64" },
{ "name": "Add-DifferentSign-64" },
{ "name": "Add-SameSign-128" },
{ "name": "Add-DifferentSign-128" },
{ "name": "Add-SameSign-256" },
{ "name": "Add-DifferentSign-256" },
{ "name": "Add-SameSign-512" },
{ "name": "Add-DifferentSign-512" },
{ "name": "Add-SameSign-1024" },
{ "name": "Add-DifferentSign-1024" },
{ "name": "Add-SameSign-2048" },
{ "name": "Add-DifferentSign-2048" },
{ "name": "Add-SameSign-4096" },
{ "name": "Add-DifferentSign-4096" },
{ "name": "Add-SameSign-8192" },
{ "name": "Add-DifferentSign-8192" },
{ "name": "Add-Random" }
]
},
{
"name": "Add-No-Opt",
"main": "run.js",
"flags": ["--allow-natives-syntax", "--no-turbofan"],
"resources": ["add-no-opt.js", "bigint-util.js"],
"test_flags": ["add-no-opt"],
"results_regexp": "^BigInt\\-%s\\(Score\\): (.+)$",
"tests": [
{ "name": "Add-Small" },
{ "name": "Add-Large" },
{ "name": "Add-LargerThanSmall" },
{ "name": "Add-Random" }
]
},
{
"name": "Subtract",
"main": "run.js",
@ -150,24 +123,13 @@
"test_flags": ["subtract"],
"results_regexp": "^BigInt\\-%s\\(Score\\): (.+)$",
"tests": [
{ "name": "Subtract-TypeError" },
{ "name": "Subtract-Zero" },
{ "name": "Subtract-SameSign-32" },
{ "name": "Subtract-DifferentSign-32" },
{ "name": "Subtract-SameSign-64" },
{ "name": "Subtract-DifferentSign-64" },
{ "name": "Subtract-SameSign-128" },
{ "name": "Subtract-DifferentSign-128" },
{ "name": "Subtract-SameSign-256" },
{ "name": "Subtract-DifferentSign-256" },
{ "name": "Subtract-SameSign-512" },
{ "name": "Subtract-DifferentSign-512" },
{ "name": "Subtract-SameSign-1024" },
{ "name": "Subtract-DifferentSign-1024" },
{ "name": "Subtract-SameSign-2048" },
{ "name": "Subtract-DifferentSign-2048" },
{ "name": "Subtract-SameSign-4096" },
{ "name": "Subtract-DifferentSign-4096" },
{ "name": "Subtract-SameSign-8192" },
{ "name": "Subtract-DifferentSign-8192" },
{ "name": "Subtract-Random" }
@ -215,17 +177,6 @@
{ "name": "BitwiseAnd-Random" }
]
},
{
"name": "Exponentiate",
"main": "run.js",
"flags": ["--allow-natives-syntax"],
"resources": ["exponentiate.js", "bigint-util.js"],
"test_flags": ["exponentiate"],
"results_regexp": "^BigInt\\-%s\\(Score\\): (.+)$",
"tests": [
{ "name": "Exponentiate-Base-Two" }
]
},
{
"name": "AsUintN",
"main": "run.js",