benchmark script
This commit is contained in:
558990
data/en-dictionary.dict
558990
data/en-dictionary.dict
File diff suppressed because it is too large
Load Diff
@@ -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();
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user