Commit 62d26420 authored by Joyee Cheung's avatar Joyee Cheung Committed by V8 LUCI CQ

[class] add microbenchmark for computed class fields

Bug: v8:10793
Change-Id: Ic01e2073b18d6f56c2ce708e17726c64ec58e141
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3216972Reviewed-by: 's avatarShu-yu Guo <syg@chromium.org>
Commit-Queue: Joyee Cheung <joyee@igalia.com>
Cr-Commit-Position: refs/heads/main@{#77330}
parent 29d8a4ee
......@@ -36,7 +36,8 @@
"name": "evaluate-class-private-field-single-noopt",
"main": "run.js",
"test_flags": [ "evaluate-class", "private-field-single", "noopt" ]
}, {
},
{
"name": "evaluate-class-public-field-multiple-opt",
"main": "run.js",
"test_flags": [ "evaluate-class", "public-field-multiple", "opt" ]
......@@ -55,6 +56,26 @@
"name": "evaluate-class-private-field-multiple-noopt",
"main": "run.js",
"test_flags": [ "evaluate-class", "private-field-multiple", "noopt" ]
},
{
"name": "evaluate-class-computed-field-single-opt",
"main": "run.js",
"test_flags": [ "evaluate-class", "computed-field-single", "opt" ]
},
{
"name": "evaluate-class-computed-field-single-noopt",
"main": "run.js",
"test_flags": [ "evaluate-class", "computed-field-single", "noopt" ]
},
{
"name": "evaluate-class-computed-field-multiple-opt",
"main": "run.js",
"test_flags": [ "evaluate-class", "computed-field-multiple", "opt" ]
},
{
"name": "evaluate-class-computed-field-multiple-noopt",
"main": "run.js",
"test_flags": [ "evaluate-class", "computed-field-multiple", "noopt" ]
}
]
},
......@@ -113,6 +134,34 @@
"test_flags": [ "define-private-field", "multiple", "noopt" ]
}
]
},
{
"name": "define-computed-field",
"resources": [ "define-computed-field.js", "classes.js" ],
"flags": ["--allow-natives-syntax"],
"results_regexp": "^%s\\-ClassFields\\(Score\\): (.+)$",
"tests": [
{
"name": "define-computed-field-single-opt",
"main": "run.js",
"test_flags": [ "define-computed-field", "single", "opt" ]
},
{
"name": "define-computed-field-single-noopt",
"main": "run.js",
"test_flags": [ "define-computed-field", "single", "noopt" ]
},
{
"name": "define-computed-field-multiple-opt",
"main": "run.js",
"test_flags": [ "define-computed-field", "multiple", "opt" ]
},
{
"name": "define-computed-field-multiple-noopt",
"main": "run.js",
"test_flags": [ "define-computed-field", "multiple", "noopt" ]
}
]
}
]
}
......@@ -57,3 +57,34 @@ function EvaluateMultiPrivateFieldClass() {
}
};
}
function key(i) {
return 'abcdefghijklmnopqrstuvwxyz'[i];
}
function EvaluateSingleComputedFieldClass() {
return class SingleComputedFieldClass {
[key(0)] = i;
check() {
return this[key(0)] === i;
}
}
}
function EvaluateMultiComputedFieldClass() {
return class MultiComputedFieldClass {
[key(0)] = i;
[key(1)] = i+1;
[key(2)] = i+2;
[key(3)] = i+3;
[key(4)] = i+4;
[key(5)] = i+5;
check() {
return this[key(0)] + 1 === this[key(1)] && this[key(1)] + 1 === this[key(2)] &&
this[key(2)] + 1 === this[key(3)] && this[key(3)] + 1 === this[key(4)] &&
this[key(4)] + 1 === this[key(5)];
}
};
}
// 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('classes.js');
const BENCHMARK_NAME = arguments[0];
const TEST_TYPE = arguments[1];
const optimize_param = arguments[2];
let optimize;
if (optimize_param == "opt") {
optimize = true;
} else if (optimize_param == "noopt"){
optimize = false;
} else {
throw new Error("Unknown optimization configuration " + arguments.join(' '));
}
let klass;
let array;
switch (TEST_TYPE) {
case "single":
klass = EvaluateSingleComputedFieldClass();
break;
case "multiple":
klass = EvaluateMultiComputedFieldClass();
break;
default:
throw new Error("Unknown optimization configuration " + arguments.join(' '));
}
if (optimize) {
%PrepareFunctionForOptimization(klass);
} else {
%NeverOptimizeFunction(klass);
}
function setUp() {
array = [new klass(), new klass()];
// Populate the array first to reduce the impact of
// array allocations.
for (let i = 0; i < LOCAL_ITERATIONS - 2; ++i) {
array.push(array[0]);
}
if (optimize) {
%OptimizeFunctionOnNextCall(klass);
}
}
function runBenchmark() {
for (let i = 0; i < LOCAL_ITERATIONS; ++i) {
array[i] = new klass();
}
}
function tearDown() {
if (array.length < 3) {
throw new Error(`Check failed, array length ${array.length}`);
}
for (const instance of array) {
if (!instance.check())
throw new Error(`instance.check() failed`);
}
}
const DETERMINISTIC_RUNS = 1;
const LOCAL_ITERATIONS = 10000;
new BenchmarkSuite(`${BENCHMARK_NAME}`, [1000], [
new Benchmark(
`${BENCHMARK_NAME}-${TEST_TYPE}-${optimize_param}`,
false, false, DETERMINISTIC_RUNS, runBenchmark, setUp, tearDown)
]);
......@@ -33,6 +33,12 @@ switch (TEST_TYPE) {
case "private-field-multiple":
factory = EvaluateMultiPrivateFieldClass;
break;
case "computed-field-single":
factory = EvaluateSingleComputedFieldClass;
break;
case "computed-field-multiple":
factory = EvaluateMultiComputedFieldClass;
break;
default:
throw new Error("Unknown optimization configuration " + arguments.join(' '));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment