From 3a6e16ee2b3b855b8b1680d0c1bcb0db2f91d38a Mon Sep 17 00:00:00 2001 From: themodernhakr Date: Wed, 26 Mar 2025 08:55:15 -0500 Subject: [PATCH] Move benchmarks to separate modules --- src/database/benchmark.jmc | 110 ++++++++++++++++++++++++++++++++++++ src/database/database.jmc | 112 +------------------------------------ 2 files changed, 112 insertions(+), 110 deletions(-) create mode 100644 src/database/benchmark.jmc diff --git a/src/database/benchmark.jmc b/src/database/benchmark.jmc new file mode 100644 index 0000000..0390c7a --- /dev/null +++ b/src/database/benchmark.jmc @@ -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(); + } +} diff --git a/src/database/database.jmc b/src/database/database.jmc index 87ebecb..525a795 100644 --- a/src/database/database.jmc +++ b/src/database/database.jmc @@ -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(); - } -}