benchmark script
This commit is contained in:
@@ -18,9 +18,47 @@ async function main()
|
||||
await Socket.init();
|
||||
await Router.init();
|
||||
|
||||
// benchmarkDictionary();
|
||||
|
||||
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();
|
||||
|
||||
|
||||
@@ -37,29 +37,36 @@ function LoadTextDictionaries()
|
||||
}
|
||||
}
|
||||
|
||||
function GenerateDictionaryTrees()
|
||||
function Optimise()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
function FindWord(lang, word)
|
||||
{
|
||||
let ret = "";
|
||||
word = word.toUpperCase();
|
||||
|
||||
let ret = false;
|
||||
for (const language of Dictionaries)
|
||||
{
|
||||
|
||||
if (language.lang !== lang) continue;
|
||||
|
||||
|
||||
if (language.optimised)
|
||||
{
|
||||
|
||||
|
||||
|
||||
} else
|
||||
{
|
||||
if (language.data.includes(word)) ret = true;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
LoadTextDictionaries: LoadTextDictionaries,
|
||||
GenerateDictionaryTrees: GenerateDictionaryTrees,
|
||||
Optimise: Optimise,
|
||||
FindWord: FindWord
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user