[js-perf-test] Adds performance benchmarks for BigInt.asUintN

Bug: v8:9213
Change-Id: I05f56f7bdd8d15f2ae992a97529fba18f0644c55
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1678417
Commit-Queue: Nico Hartmann <nicohartmann@google.com>
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Reviewed-by: Sigurd Schneider <sigurds@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62461}
This commit is contained in:
Nico Hartmann 2019-06-28 16:03:11 +02:00 committed by Commit Bot
parent bc4cbe927a
commit 13debbe1e8
5 changed files with 114 additions and 7 deletions

View File

@ -6,11 +6,6 @@
load('bigint-util.js'); load('bigint-util.js');
const TEST_ITERATIONS = 1000;
const SLOW_TEST_ITERATIONS = 50;
const BITS_CASES = [32, 64, 128, 256, 512, 1024, 2048, 4096, 8192];
const RANDOM_BIGINTS_MAX_BITS = 64 * 100;
let initial_sum = 0n; let initial_sum = 0n;
let a = 0n; let a = 0n;
let random_bigints = []; let random_bigints = [];

View File

@ -0,0 +1,86 @@
// Copyright 2019 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";
load('bigint-util.js');
// 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(`AsUint64-${d}`, [1000], [
new Benchmark(`AsUint64-${d}`, true, false, 0, TestAsUint64,
() => SetUpTestAsUintN(d))
]);
});
[32, 64, 128, 256].forEach((d) => {
new BenchmarkSuite(`AsUint32-${d}`, [1000], [
new Benchmark(`AsUint32-${d}`, true, false, 0, TestAsUint32,
() => SetUpTestAsUintN(d))
]);
});
[32, 64, 128, 256].forEach((d) => {
new BenchmarkSuite(`AsUint8-${d}`, [1000], [
new Benchmark(`AsUint8-${d}`, true, false, 0, TestAsUint8,
() => SetUpTestAsUintN(d))
]);
});
function SetUpTestAsUintN(d) {
random_bigints = [
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d),
RandomBigIntWithBits(d)
];
}
function TestAsUint64() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
result = BigInt.asUintN(64, random_bigints[i % 8]);
}
return result;
}
function TestAsUint32() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
result = BigInt.asUintN(32, random_bigints[i % 8]);
}
return result;
}
function TestAsUint8() {
let result = 0n;
for (let i = 0; i < TEST_ITERATIONS; ++i) {
result = BigInt.asUintN(8, random_bigints[i % 8]);
}
return result;
}

View File

@ -5,8 +5,10 @@
"use strict"; "use strict";
load('../base.js'); load('../base.js');
load('test-config.js');
load('to-boolean.js'); load('to-boolean.js');
load('add.js'); load('add.js');
load('as-uint-n.js');
var success = true; var success = true;

View File

@ -0,0 +1,10 @@
// Copyright 2019 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";
const TEST_ITERATIONS = 1000;
const SLOW_TEST_ITERATIONS = 50;
const BITS_CASES = [32, 64, 128, 256, 512, 1024, 2048, 4096, 8192];
const RANDOM_BIGINTS_MAX_BITS = 64 * 100;

View File

@ -51,8 +51,10 @@
"main": "run.js", "main": "run.js",
"resources": [ "resources": [
"bigint-util.js", "bigint-util.js",
"test-config.js",
"to-boolean.js", "to-boolean.js",
"add.js" "add.js",
"as-uint-n.js"
], ],
"results_regexp": "^%s\\-BigInt\\(Score\\): (.+)$", "results_regexp": "^%s\\-BigInt\\(Score\\): (.+)$",
"tests": [ "tests": [
@ -79,7 +81,19 @@
{ "name": "Add-DifferentSign-4096" }, { "name": "Add-DifferentSign-4096" },
{ "name": "Add-SameSign-8192" }, { "name": "Add-SameSign-8192" },
{ "name": "Add-DifferentSign-8192" }, { "name": "Add-DifferentSign-8192" },
{ "name": "Add-Random" } { "name": "Add-Random" },
{ "name": "AsUint64-32" },
{ "name": "AsUint64-64" },
{ "name": "AsUint64-128" },
{ "name": "AsUint64-256" },
{ "name": "AsUint32-32" },
{ "name": "AsUint32-64" },
{ "name": "AsUint32-128" },
{ "name": "AsUint32-256" },
{ "name": "AsUint8-32" },
{ "name": "AsUint8-64" },
{ "name": "AsUint8-128" },
{ "name": "AsUint8-256" }
] ]
}, },
{ {