v8/test/js-perf-test/ClassFields/classes.js
Joyee Cheung 1ec4c33457 [class] add microbenchmarks for private methods
Bug: v8:10793
Change-Id: If9e4884ae1817121d9661eedc1e8806ab7f68214
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3256998
Commit-Queue: Joyee Cheung <joyee@igalia.com>
Reviewed-by: Shu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77748}
2021-11-06 05:40:22 +00:00

118 lines
2.4 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";
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;
}
};
}
function EvaluateSinglePrivateMethodClass() {
return class PrivateSingleMethodClass {
#x() { return 0; }
check() {
return this.#x() === 0;
}
};
}
function EvaluateMultiPrivateMethodClass() {
return class PrivateMultiMethodClass {
#x() { return 0; }
#y() { return 1; }
#z() { return 2; }
#q() { return 3; }
#r() { return 4; }
#a() { return 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 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)];
}
};
}