Commit 862391b9 authored by Joyee Cheung's avatar Joyee Cheung Committed by V8 LUCI CQ

[class] add microbenchmark for evaluating classes with fields

Taken from https://chromium-review.googlesource.com/c/v8/v8/+/2944249

Bug: v8:10793
Change-Id: I7bd0ed9b4af48d3cade6cd98b49a1733f3101da3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3105650Reviewed-by: 's avatarShu-yu Guo <syg@chromium.org>
Commit-Queue: Joyee Cheung <joyee@igalia.com>
Cr-Commit-Position: refs/heads/main@{#76501}
parent ba9ccd97
{
"owners": ["caitp@igalia.com", "joyee@igalia.com"],
"name": "ClassFields",
"path": ["ClassFields"],
"run_count": 3,
"run_count_arm": 1,
"run_count_arm64": 1,
......@@ -11,10 +12,56 @@
"resources": ["base.js"],
"tests": [
{
"name": "ClassFields",
"path": ["ClassFields"],
"name": "evaluate-class",
"flags": ["--allow-natives-syntax"],
"resources": [ "define-public-field.js" ],
"resources": [ "evaluate-class.js", "classes.js" ],
"results_regexp": "^%s\\-ClassFields\\(Score\\): (.+)$",
"tests": [
{
"name": "evaluate-class-public-field-single-opt",
"main": "run.js",
"test_flags": [ "evaluate-class", "public-field-single", "opt" ]
},
{
"name": "evaluate-class-public-field-single-noopt",
"main": "run.js",
"test_flags": [ "evaluate-class", "public-field-single", "noopt" ]
},
{
"name": "evaluate-class-private-field-single-opt",
"main": "run.js",
"test_flags": [ "evaluate-class", "private-field-single", "opt" ]
},
{
"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" ]
},
{
"name": "evaluate-class-public-field-multiple-noopt",
"main": "run.js",
"test_flags": [ "evaluate-class", "public-field-multiple", "noopt" ]
},
{
"name": "evaluate-class-private-field-multiple-opt",
"main": "run.js",
"test_flags": [ "evaluate-class", "private-field-multiple", "opt" ]
},
{
"name": "evaluate-class-private-field-multiple-noopt",
"main": "run.js",
"test_flags": [ "evaluate-class", "private-field-multiple", "noopt" ]
}
]
},
{
"name": "define-public-field",
"flags": ["--allow-natives-syntax"],
"resources": [ "define-public-field.js", "classes.js" ],
"results_regexp": "^%s\\-ClassFields\\(Score\\): (.+)$",
"tests": [
{
......@@ -36,7 +83,15 @@
"name": "define-public-field-multiple-noopt",
"main": "run.js",
"test_flags": [ "define-public-field", "multiple", "noopt" ]
},
}
]
},
{
"name": "define-private-field",
"resources": [ "define-private-field.js", "classes.js" ],
"flags": ["--allow-natives-syntax"],
"results_regexp": "^%s\\-ClassFields\\(Score\\): (.+)$",
"tests": [
{
"name": "define-private-field-single-opt",
"main": "run.js",
......
// 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";
let i = 0;
function EvaluateSinglePublicFieldClass() {
return class SinglePublicFieldClass {
x = i;
check() {
return this.x === i;
}
};
}
function EvaluateMultiPublicFieldClass() {
return class MultiPublicFieldClass {
x = i;
y = i+1;
z = i+2;
q = i+3;
r = i+4;
a = i+5;
check() {
return this.x + 1 === this.y && this.y + 1 === this.z &&
this.z + 1 === this.q && this.q + 1 === this.r &&
this.r + 1 === this.a;
}
};
}
function EvaluateSinglePrivateFieldClass() {
return class SinglePrivateFieldClass {
#x = i;
check() {
return this.#x === i;
}
}
}
function EvaluateMultiPrivateFieldClass() {
return class MultiPrivateFieldClass {
#x = i;
#y = i+1;
#z = i+2;
#q = i+3;
#r = i+4;
#a = i+5;
check() {
return this.#x + 1 === this.#y && this.#y + 1 === this.#z &&
this.#z + 1 === this.#q && this.#q + 1 === this.#r &&
this.#r + 1 === this.#a;
}
};
}
......@@ -3,6 +3,8 @@
// 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];
......@@ -16,38 +18,14 @@ if (optimize_param == "opt") {
}
let klass;
let i = 0;
let array;
class SinglePrivateFieldClass {
#x = i;
check() {
return this.#x === i;
}
}
class MultiPrivateFieldClass {
#x = i;
#y = i+1;
#z = i+2;
#q = i+3;
#r = i+4;
#a = i+5;
check() {
return this.#x + 1 === this.#y && this.#y + 1 === this.#z &&
this.#z + 1 === this.#q && this.#q + 1 === this.#r &&
this.#r + 1 === this.#a;
}
}
switch (TEST_TYPE) {
case "single":
klass = SinglePrivateFieldClass;
klass = EvaluateSinglePrivateFieldClass();
break;
case "multiple":
klass = MultiPrivateFieldClass;
klass = EvaluateMultiPrivateFieldClass();
break;
default:
throw new Error("Unknown optimization configuration " + arguments.join(' '));
......
......@@ -3,6 +3,8 @@
// 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];
......@@ -16,38 +18,14 @@ if (optimize_param == "opt") {
}
let klass;
let i = 0;
let array;
class SinglePublicFieldClass {
x = i;
check() {
return this.x === i;
}
}
class MultiPublicFieldClass {
x = i;
y = i+1;
z = i+2;
q = i+3;
r = i+4;
a = i+5;
check() {
return this.x + 1 === this.y && this.y + 1 === this.z &&
this.z + 1 === this.q && this.q + 1 === this.r &&
this.r + 1 === this.a;
}
}
switch (TEST_TYPE) {
case "single":
klass = SinglePublicFieldClass;
klass = EvaluateSinglePublicFieldClass();
break;
case "multiple":
klass = MultiPublicFieldClass;
klass = EvaluateMultiPublicFieldClass();
break;
default:
throw new Error("Unknown optimization configuration " + arguments.join(' '));
......
// 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 factory;
let array;
switch (TEST_TYPE) {
case "public-field-single":
factory = EvaluateSinglePublicFieldClass;
break;
case "public-field-multiple":
factory = EvaluateMultiPublicFieldClass;
break;
case "private-field-single":
factory = EvaluateSinglePrivateFieldClass;
break;
case "private-field-multiple":
factory = EvaluateMultiPrivateFieldClass;
break;
default:
throw new Error("Unknown optimization configuration " + arguments.join(' '));
}
if (optimize) {
%PrepareFunctionForOptimization(factory);
} else {
%NeverOptimizeFunction(factory);
}
function setUp() {
array = [factory(), factory()];
// 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(factory);
}
}
function runBenchmark() {
for (let i = 0; i < LOCAL_ITERATIONS; ++i) {
array[i] = factory();
}
}
function tearDown() {
if (array.length < 3) {
throw new Error(`Check failed, array length ${array.length}`);
}
for (const klass of array) {
const instance = new klass();
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)
]);
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