benchmark script

This commit is contained in:
Ben Kyd
2021-04-12 23:39:16 +01:00
parent 932a530ab3
commit 98f1e9f09e
3 changed files with 279546 additions and 279501 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -18,9 +18,47 @@ async function main()
await Socket.init(); await Socket.init();
await Router.init(); await Router.init();
// benchmarkDictionary();
Logger.ready(); Logger.ready();
} }
function benchmarkDictionary()
{
let hrTime = process.hrtime();
let startTime = hrTime[0] * 1000000 + hrTime[1] / 1000;
// Time 10 thousand reads
for (let i = 0; i < 10000; i++)
{
Dict.FindWord('en', 'ZZZS');
}
hrTime = process.hrtime();
let endTime = hrTime[0] * 1000000 + hrTime[1] / 1000;
Logger.debug(`10 000 Reads (unoptimised): ${endTime - startTime}μs`)
Dict.Optimise();
hrTime = process.hrtime();
startTime = hrTime[0] * 1000000 + hrTime[1] / 1000;
// Time 10 thousand reads
for (let i = 0; i < 10000; i++)
{
Dict.FindWord('en', 'ZZZS');
}
hrTime = process.hrtime();
endTime = hrTime[0] * 1000000 + hrTime[1] / 1000;
Logger.debug(`10 000 Reads (optimised): ${endTime - startTime}μs`)
}
main(); main();

View File

@@ -37,29 +37,36 @@ function LoadTextDictionaries()
} }
} }
function GenerateDictionaryTrees() function Optimise()
{ {
} }
function FindWord(lang, word) function FindWord(lang, word)
{ {
let ret = ""; word = word.toUpperCase();
let ret = false;
for (const language of Dictionaries) for (const language of Dictionaries)
{ {
if (language.lang !== lang) continue; if (language.lang !== lang) continue;
if (language.optimised)
{
} else
{
if (language.data.includes(word)) ret = true;
}
} }
return ret;
} }
module.exports = { module.exports = {
LoadTextDictionaries: LoadTextDictionaries, LoadTextDictionaries: LoadTextDictionaries,
GenerateDictionaryTrees: GenerateDictionaryTrees, Optimise: Optimise,
FindWord: FindWord FindWord: FindWord
}; };