Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

View File

@ -0,0 +1,23 @@
// Copyright 2018 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.
d8.file.execute('../base.js');
d8.file.execute(arguments[0] + '.js')
function PrintResult(name, result) {
print(name + '-ArraySort(Score): ' + result);
}
function PrintStep(name) {}
function PrintError(name, error) {
PrintResult(name, error);
}
BenchmarkSuite.config.doWarmup = undefined;
BenchmarkSuite.config.doDeterministic = undefined;
BenchmarkSuite.RunSuites({ NotifyResult: PrintResult,
NotifyError: PrintError,
NotifyStep: PrintStep });

View File

@ -0,0 +1,141 @@
// Copyright 2018 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.
const kArraySize = 4000;
let template_array = [];
for (let i = 0; i < kArraySize; ++i) {
template_array[i] = Math.floor(Math.random() * kArraySize);
}
let array_to_sort = [];
function AssertPackedSmiElements() {
assert(%HasFastPackedElements(array_to_sort) &&
%HasSmiElements(array_to_sort),
"Element kind is not PACKED_SMI_ELEMENTS");
}
function AssertPackedDoubleElements() {
assert(%HasFastPackedElements(array_to_sort) &&
%HasDoubleElements(array_to_sort),
"Element kind is not PACKED_DOUBLE_ELEMENTS");
}
function AssertPackedObjectElements() {
assert(%HasFastPackedElements(array_to_sort) &&
%HasObjectElements(array_to_sort),
"Element kind is not PACKED_ELEMENTS");
}
function AssertHoleySmiElements() {
assert(%HasHoleyElements(array_to_sort) &&
%HasSmiElements(array_to_sort),
"Element kind is not HOLEY_SMI_ELEMENTS");
}
function AssertHoleyDoubleElements() {
assert(%HasHoleyElements(array_to_sort) &&
%HasDoubleElements(array_to_sort),
"Element kind is not HOLEY_DOUBLE_ELEMENTS");
}
function AssertHoleyObjectElements() {
assert(%HasHoleyElements(array_to_sort) &&
%HasObjectElements(array_to_sort),
"Element kind is not HOLEY_ELEMENTS");
}
function AssertDictionaryElements() {
assert(%HasDictionaryElements(array_to_sort),
"Element kind is not DICTIONARY_ELEMENTS");
}
function CreatePackedSmiArray() {
array_to_sort = Array.from(template_array);
AssertPackedSmiElements();
}
function CreatePackedDoubleArray() {
array_to_sort = Array.from(template_array, (x,_) => x + 0.1);
AssertPackedDoubleElements();
}
function CreatePackedObjectArray() {
array_to_sort = Array.from(template_array, (x,_) => `value ${x}`);
AssertPackedObjectElements();
}
function CreateHoleySmiArray() {
array_to_sort = Array.from(template_array);
delete array_to_sort[0];
AssertHoleySmiElements();
}
function CreateHoleyDoubleArray() {
array_to_sort = new Array(kArraySize);
for (let i = 0; i < kArraySize; ++i) {
array_to_sort[i] = template_array[i] + 0.1;
}
AssertHoleyDoubleElements();
}
function CreateHoleyObjectArray() {
array_to_sort = new Array(kArraySize);
for (let i = 0; i < kArraySize; ++i) {
array_to_sort[i] = `value ${template_array[i]}`;
}
AssertHoleyObjectElements();
}
function CreateDictionaryArray() {
array_to_sort = Array.from(template_array);
Object.defineProperty(array_to_sort, kArraySize - 2,
{ get: () => this.foo,
set: (v) => this.foo = v });
AssertDictionaryElements();
}
function Sort() {
array_to_sort.sort();
}
function CreateSortFn(comparefns = []) {
return () => {
for (let cmpfn of comparefns) {
array_to_sort.sort(cmpfn);
}
}
}
function cmp_smaller(a, b) {
if (a < b) return -1;
if (b < a) return 1;
return 0;
}
function cmp_greater(a, b) { return cmp_smaller(b, a); }
// The counter is used in some benchmarks to trigger actions during sorting.
// To keep benchmarks deterministic, the counter needs to be reset for each
// iteration.
let counter = 0;
// Sorting benchmarks need to execute setup and tearDown for each iteration.
// Otherwise the benchmarks would mainly measure sorting already sorted arrays
// which, depending on the strategy, is either the worst- or best case.
function createSortSuite(name, reference, run, setup, tearDown = () => {}) {
let run_fn = () => {
counter = 0;
setup();
run();
tearDown();
};
return createSuite(name, reference, run_fn);
}

View File

@ -0,0 +1,43 @@
// Copyright 2018 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.
d8.file.execute('sort-base.js');
// Creates a comparison function, that will call the provided transform function
// after a set amount of comparisons. The transform function should cause the
// element kind of the array to change.
function CreateCompareFn(transformfn) {
return (a, b) => {
++counter;
if (counter == kArraySize/2) {
transformfn();
}
return cmp_smaller(a, b);
}
}
let cmp_packed_smi_to_double = CreateCompareFn(() => array_to_sort.push(0.1));
let cmp_holey_smi_to_double = CreateCompareFn(() => array_to_sort.push(0.1));
let cmp_double_to_double = CreateCompareFn(() => array_to_sort.length *= 2);
createSortSuite(
'PackedSmiToPackedDouble', 1000, CreateSortFn([cmp_packed_smi_to_double]),
CreatePackedSmiArray, AssertPackedDoubleElements);
createSortSuite(
'HoleySmiToHoleyDouble', 1000, CreateSortFn([cmp_holey_smi_to_double]),
CreateHoleySmiArray, AssertHoleyDoubleElements);
createSortSuite(
'PackedDoubleToHoleyDouble', 1000, CreateSortFn([cmp_double_to_double]),
CreatePackedDoubleArray, AssertHoleyDoubleElements);
let cmp_packed_to_dict = CreateCompareFn(() => array_to_sort[%MaxSmi()] = 42);
let cmp_holey_to_dict = CreateCompareFn(() => array_to_sort[%MaxSmi()] = 42);
createSortSuite(
'PackedElementToDictionary', 1000, CreateSortFn([cmp_packed_to_dict]),
CreatePackedObjectArray, AssertDictionaryElements);
createSortSuite(
'HoleyElementToDictionary', 1000, CreateSortFn([cmp_holey_to_dict]),
CreateHoleyObjectArray, AssertDictionaryElements);

View File

@ -0,0 +1,20 @@
// Copyright 2018 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.
d8.file.execute('sort-base.js');
// Each benchmark calls sort with multiple different comparison functions
// to create polyomorphic call sites. Most/all of the
// other sort benchmarks have monomorphic call sites.
let sortfn = CreateSortFn([cmp_smaller, cmp_greater]);
createSortSuite('PackedSmi', 1000, sortfn, CreatePackedSmiArray);
createSortSuite('PackedDouble', 1000, sortfn, CreatePackedDoubleArray);
createSortSuite('PackedElement', 1000, sortfn, CreatePackedObjectArray);
createSortSuite('HoleySmi', 1000, sortfn, CreateHoleySmiArray);
createSortSuite('HoleyDouble', 1000, sortfn, CreateHoleyDoubleArray);
createSortSuite('HoleyElement', 1000, sortfn, CreateHoleyObjectArray);
createSortSuite('Dictionary', 1000, sortfn, CreateDictionaryArray);

View File

@ -0,0 +1,36 @@
// Copyright 2018 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.
d8.file.execute('sort-base.js');
function SortAsc() {
array_to_sort.sort(cmp_smaller);
}
function Random(length) {
array_to_sort = [];
for (let i = 0; i < length; ++i) {
array_to_sort.push(Math.floor(Math.random() * length));
}
AssertPackedSmiElements();
}
function Sorted(length) {
array_to_sort = [];
for (let i = 0; i < length; ++i) {
array_to_sort.push(i);
}
AssertPackedSmiElements();
}
function CreateSortSuitesForLength(length) {
createSortSuite('Random' + length, 1000, SortAsc, () => Random(length));
createSortSuite('Sorted' + length, 1000, SortAsc, () => Sorted(length));
}
CreateSortSuitesForLength(10);
CreateSortSuitesForLength(100);
CreateSortSuitesForLength(1000);
CreateSortSuitesForLength(10000);
CreateSortSuitesForLength(100000);

View File

@ -0,0 +1,20 @@
// Copyright 2018 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.
d8.file.execute('sort-base.js');
function SetupMegamorphic() {
CreatePackedSmiArray();
Array.prototype.sort.call([1.1]);
Array.prototype.sort.call(['a']);
Array.prototype.sort.call([2,,3]);
Array.prototype.sort.call([0.2,,0.1]);
Array.prototype.sort.call(['b',,'a']);
Array.prototype.sort.call({});
}
createSortSuite('Base', 1000, Sort, SetupMegamorphic);
createSortSuite('MultipleCompareFns', 1000,
CreateSortFn([cmp_smaller, cmp_greater]), SetupMegamorphic);

View File

@ -0,0 +1,108 @@
// Copyright 2018 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.
d8.file.execute('sort-base.js');
const kLength = 2e4;
const kLengthHalf = kLength >>> 1;
function SortAsc() {
array_to_sort.sort(cmp_smaller);
}
function Up(a, length) {
for (let i = 0; i < length; ++i) {
a.push(i);
}
}
function Down(a, length) {
for (let i = 0; i < length; ++i) {
a.push(length - i);
}
}
function SawSeq(a, tooth, length) {
let count = 0;
while (true) {
for (let i = 0; i < tooth; ++i) {
a.push(i);
if (++count >= length) return;
}
}
}
function SawSeq2(a, tooth, length) {
let count = 0;
while (true) {
for (let i = 0; i < tooth; ++i) {
a.push(i);
if (++count >= length) return;
}
for (let i = 0; i < tooth; ++i) {
a.push(tooth - i);
if (++count >= length) return;
}
}
}
function SawSeq3(a, tooth, length) {
let count = 0;
while (true) {
for (let i = 0; i < tooth; ++i) {
a.push(tooth - i);
if (++count >= length) return;
}
}
}
function Random(a, length) {
for (let i = 0; i < length; ++i) {
a.push(Math.floor(Math.random() * length));
}
}
function TearDown() {
// Sanity check that the array is sorted.
let length = array_to_sort.length - 1;
for (let i = 0; i < length; ++i) {
if (array_to_sort[i] > array_to_sort[i + 1]) {
throw "Not sorted correctly: i = " + i;
}
}
array_to_sort = [];
}
let SetupSaw1000 = () => SawSeq(array_to_sort, 1000, kLength);
let SetupSaw500 = () => SawSeq(array_to_sort, 500, kLength);
let SetupSaw200 = () => SawSeq(array_to_sort, 200, kLength);
let SetupSaw200Sym = () => SawSeq2(array_to_sort, 200, kLength);
let SetupSaw200Down = () => SawSeq3(array_to_sort, 200, kLength);
function SetupPreSortedHalfs(firstfn, secondfn) {
array_to_sort = [];
firstfn(array_to_sort, kLengthHalf);
secondfn(array_to_sort, kLengthHalf);
}
let SetupUpDown = () => SetupPreSortedHalfs(Up, Down);
let SetupUpUp = () => SetupPreSortedHalfs(Up, Up);
let SetupDownDown = () => SetupPreSortedHalfs(Down, Down);
let SetupDownUp = () => SetupPreSortedHalfs(Down, Up);
createSortSuite(
'Random', 1000, SortAsc, () => Random(array_to_sort, kLength), TearDown);
createSortSuite(
'Up', 1000, SortAsc, () => Up(array_to_sort, kLength), TearDown);
createSortSuite(
'Down', 1000, SortAsc, () => Down(array_to_sort, kLength), TearDown);
createSortSuite('Saw1000', 1000, SortAsc, SetupSaw1000, TearDown);
createSortSuite('Saw500', 1000, SortAsc, SetupSaw500, TearDown);
createSortSuite('Saw200', 1000, SortAsc, SetupSaw200, TearDown);
createSortSuite('Saw200Symmetric', 1000, SortAsc, SetupSaw200Sym, TearDown);
createSortSuite('Saw200Down', 1000, SortAsc, SetupSaw200Down, TearDown);
createSortSuite('UpDown', 1000, SortAsc, SetupUpDown, TearDown);
createSortSuite('UpUp', 1000, SortAsc, SetupUpUp, TearDown);
createSortSuite('DownDown', 1000, SortAsc, SetupDownDown, TearDown);
createSortSuite('DownUp', 1000, SortAsc, SetupDownUp, TearDown);

View File

@ -0,0 +1,15 @@
// Copyright 2018 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.
d8.file.execute('sort-base.js');
createSortSuite('PackedSmi', 1000, Sort, CreatePackedSmiArray);
createSortSuite('PackedDouble', 1000, Sort, CreatePackedDoubleArray);
createSortSuite('PackedElement', 1000, Sort, CreatePackedObjectArray);
createSortSuite('HoleySmi', 1000, Sort, CreateHoleySmiArray);
createSortSuite('HoleyDouble', 1000, Sort, CreateHoleyDoubleArray);
createSortSuite('HoleyElement', 1000, Sort, CreateHoleyObjectArray);
createSortSuite('Dictionary', 1000, Sort, CreateDictionaryArray);