Move benchmarks to separate modules
All checks were successful
Deploy datapack to dev / Build (push) Successful in 9s

This commit is contained in:
themodernhakr 2025-03-26 08:55:15 -05:00
parent 3c0eab8fd8
commit 3a6e16ee2b
2 changed files with 112 additions and 110 deletions

110
src/database/benchmark.jmc Normal file
View File

@ -0,0 +1,110 @@
class database.benchmark {
function arrayTest1.setup() {
::database.test.arrayTest1.array = [];
Hardcode.repeat(
indexString="[index]",
start=0,
stop=500,
function=() => {
::database.test.arrayTest1.array << {id: Hardcode.calc([index]+1), string: "entryHardcode.calc([index]+1)"};
}
);
}
function arrayTest1.print() {
tellraw @a {"nbt":"database.test.arrayTest1.array","storage":"ferdinland:ferdinland"};
}
function arrayTest1.clean() {
::database.test.arrayTest1.array.del();
::temp.arrayTest1.del();
}
function arrayTest1.run() {
::temp.arrayTest1 = ::database.test.arrayTest1.array;
::temp.keyword = "entry500";
Array.forEach(
"ferdinland:ferdinland",
"temp.arrayTest1",
() => {
if (Object.isEqual("ferdinland:ferdinland", "temp.arrayTest1[0].string", "ferdinland:ferdinland", "temp.keyword")) {
::temp.result = ::temp.arrayTest1[0];
}
if (Object.isEqual("ferdinland:ferdinland", "temp.arrayTest1[0].string", "ferdinland:ferdinland", "temp.keyword")) {
return;
}
}
);
::temp.arrayTest1.del();
::temp.keyword.del();
}
function arrayTest2.setup() {
::database.test.arrayTest2.array = [];
::database.test.arrayTest2.index = {};
Hardcode.repeat(
indexString="[index]",
start=0,
stop=500,
function=() => {
::database.test.arrayTest2.array << {id: Hardcode.calc([index]+1), string: "entryHardcode.calc([index]+1)"};
::database.test.arrayTest2.index += {entryHardcode.calc([index]+1): [index]};
}
);
}
function arrayTest2.printArray() {
tellraw @a {"nbt":"database.test.arrayTest2.array","storage":"ferdinland:ferdinland"};
}
function arrayTest2.printIndex() {
tellraw @a {"nbt":"database.test.arrayTest2.index","storage":"ferdinland:ferdinland"};
}
function arrayTest2.clean() {
::database.test.arrayTest2.array.del();
::database.test.arrayTest2.index.del();
}
function arrayTest2._searchIndex() {
$::temp.index = ::database.test.arrayTest2.index.$(keyword);
}
function arrayTest2._searchArray() {
$::temp.result = ::database.test.arrayTest2.array[$(index)];
}
function arrayTest2.run() {
::temp.keyword = "entry500";
this.arrayTest2._searchIndex() with ::temp;
this.arrayTest2._searchArray() with ::temp;
::temp.keyword.del();
::temp.index.del();
::temp.result.del();
}
function arrayTest3.setup() {
::database.test.arrayTest3.array = [];
::database.test.arrayTest3.index = {};
Hardcode.repeat(
indexString="[index]",
start=0,
stop=500,
function=() => {
::database.test.arrayTest3.array << {id: Hardcode.calc([index]+1), string: "entryHardcode.calc([index]+1)"};
::database.test.arrayTest3.index += {entryHardcode.calc([index]+1): [index]};
}
);
}
function arrayTest3.printArray() {
tellraw @a {"nbt":"database.test.arrayTest3.array","storage":"ferdinland:ferdinland"};
}
function arrayTest3.printIndex() {
tellraw @a {"nbt":"database.test.arrayTest3.index","storage":"ferdinland:ferdinland"};
}
function arrayTest3.clean() {
::database.test.arrayTest3.array.del();
::database.test.arrayTest3.index.del();
}
function arrayTest3._searchArray() {
$::temp.result = ::database.test.arrayTest3.array[string:$(keyword)];
}
function arrayTest3.run() {
::temp.keyword = "entry500";
this.arrayTest3._searchArray() with ::temp;
::temp.keyword.del();
::temp.result.del();
}
}

View File

@ -1,3 +1,5 @@
import "benchmark.jmc";
@lazy //takes name of table. metadata must already exist.
function createTable(name) {
logger(2, database.createTable, "Creating table: $name");
@ -23,113 +25,3 @@ class database {
}
}
class database.benchmark {
function arrayTest1.setup() {
::database.test.arrayTest1.array = [];
Hardcode.repeat(
indexString="[index]",
start=0,
stop=500,
function=() => {
::database.test.arrayTest1.array << {id: Hardcode.calc([index]+1), string: "entryHardcode.calc([index]+1)"};
}
);
}
function arrayTest1.print() {
tellraw @a {"nbt":"database.test.arrayTest1.array","storage":"ferdinland:ferdinland"};
}
function arrayTest1.clean() {
::database.test.arrayTest1.array.del();
::temp.arrayTest1.del();
}
function arrayTest1.run() {
::temp.arrayTest1 = ::database.test.arrayTest1.array;
::temp.keyword = "entry500";
Array.forEach(
"ferdinland:ferdinland",
"temp.arrayTest1",
() => {
if (Object.isEqual("ferdinland:ferdinland", "temp.arrayTest1[0].string", "ferdinland:ferdinland", "temp.keyword")) {
::temp.result = ::temp.arrayTest1[0];
}
if (Object.isEqual("ferdinland:ferdinland", "temp.arrayTest1[0].string", "ferdinland:ferdinland", "temp.keyword")) {
return;
}
}
);
::temp.arrayTest1.del();
::temp.keyword.del();
}
function arrayTest2.setup() {
::database.test.arrayTest2.array = [];
::database.test.arrayTest2.index = {};
Hardcode.repeat(
indexString="[index]",
start=0,
stop=500,
function=() => {
::database.test.arrayTest2.array << {id: Hardcode.calc([index]+1), string: "entryHardcode.calc([index]+1)"};
::database.test.arrayTest2.index += {entryHardcode.calc([index]+1): [index]};
}
);
}
function arrayTest2.printArray() {
tellraw @a {"nbt":"database.test.arrayTest2.array","storage":"ferdinland:ferdinland"};
}
function arrayTest2.printIndex() {
tellraw @a {"nbt":"database.test.arrayTest2.index","storage":"ferdinland:ferdinland"};
}
function arrayTest2.clean() {
::database.test.arrayTest2.array.del();
::database.test.arrayTest2.index.del();
}
function arrayTest2._searchIndex() {
$::temp.index = ::database.test.arrayTest2.index.$(keyword);
}
function arrayTest2._searchArray() {
$::temp.result = ::database.test.arrayTest2.array[$(index)];
}
function arrayTest2.run() {
::temp.keyword = "entry500";
this.arrayTest2._searchIndex() with ::temp;
this.arrayTest2._searchArray() with ::temp;
::temp.keyword.del();
::temp.index.del();
::temp.result.del();
}
function arrayTest3.setup() {
::database.test.arrayTest3.array = [];
::database.test.arrayTest3.index = {};
Hardcode.repeat(
indexString="[index]",
start=0,
stop=500,
function=() => {
::database.test.arrayTest3.array << {id: Hardcode.calc([index]+1), string: "entryHardcode.calc([index]+1)"};
::database.test.arrayTest3.index += {entryHardcode.calc([index]+1): [index]};
}
);
}
function arrayTest3.printArray() {
tellraw @a {"nbt":"database.test.arrayTest3.array","storage":"ferdinland:ferdinland"};
}
function arrayTest3.printIndex() {
tellraw @a {"nbt":"database.test.arrayTest3.index","storage":"ferdinland:ferdinland"};
}
function arrayTest3.clean() {
::database.test.arrayTest3.array.del();
::database.test.arrayTest3.index.del();
}
function arrayTest3._searchArray() {
$::temp.result = ::database.test.arrayTest3.array[string:$(keyword)];
}
function arrayTest3.run() {
::temp.keyword = "entry500";
this.arrayTest3._searchArray() with ::temp;
::temp.keyword.del();
::temp.result.del();
}
}