2019-12-10 11:44:35 +02:00
|
|
|
import {Config} from '../src/common/config/private/Config';
|
|
|
|
import {ProjectPath} from '../src/backend/ProjectPath';
|
2020-12-30 22:13:19 +02:00
|
|
|
import {BenchmarkResult, BenchmarkRunner} from './BenchmarkRunner';
|
2019-12-10 11:44:35 +02:00
|
|
|
import {Utils} from '../src/common/Utils';
|
2020-12-28 23:08:57 +02:00
|
|
|
import {BMConfig} from './BMConfig';
|
2022-03-21 23:29:00 +02:00
|
|
|
import {DirectoryDTOUtils} from '../src/common/entities/DirectoryDTO';
|
2019-01-27 01:03:40 +02:00
|
|
|
|
2020-12-28 23:08:57 +02:00
|
|
|
|
2022-12-28 20:12:18 +02:00
|
|
|
Config.Media.folder = BMConfig.path;
|
2019-01-27 01:03:40 +02:00
|
|
|
ProjectPath.reset();
|
2020-12-30 22:13:19 +02:00
|
|
|
const RUNS = BMConfig.RUNS;
|
2019-01-27 01:03:40 +02:00
|
|
|
|
|
|
|
let resultsText = '';
|
|
|
|
const printLine = (text: string) => {
|
|
|
|
resultsText += text + '\n';
|
|
|
|
};
|
|
|
|
|
2020-12-30 22:54:07 +02:00
|
|
|
|
|
|
|
const printHeader = async (statistic: string) => {
|
2019-01-27 01:03:40 +02:00
|
|
|
const dt = new Date();
|
2022-12-28 20:12:18 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
2019-01-27 01:03:40 +02:00
|
|
|
printLine('## PiGallery2 v' + require('./../package.json').version +
|
2019-01-27 06:47:43 +02:00
|
|
|
', ' + Utils.zeroPrefix(dt.getDate(), 2) +
|
2019-01-27 01:03:40 +02:00
|
|
|
'.' + Utils.zeroPrefix(dt.getMonth() + 1, 2) +
|
|
|
|
'.' + dt.getFullYear());
|
2022-12-28 20:12:18 +02:00
|
|
|
if (Config.Environment && Config.Environment.buildCommitHash) {
|
|
|
|
printLine('**Version**: v' + Config.Environment.appVersion + ', built at: ' + new Date(Config.Environment.buildTime) + ', git commit:' + Config.Environment.buildCommitHash);
|
2021-05-12 12:39:30 +02:00
|
|
|
}
|
2020-12-28 23:08:57 +02:00
|
|
|
printLine('**System**: ' + BMConfig.system);
|
2020-12-30 22:54:07 +02:00
|
|
|
printLine('\n**Gallery**: ' + statistic + '\n');
|
2019-01-27 01:03:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const printTableHeader = () => {
|
2020-12-31 13:35:28 +02:00
|
|
|
printLine('| Action | Sub action | Average Duration | Result |');
|
|
|
|
printLine('|:------:|:----------:|:----------------:|:-------:|');
|
2019-01-27 01:03:40 +02:00
|
|
|
};
|
2021-05-13 09:56:36 +02:00
|
|
|
const printExperimentResult = (result: BenchmarkResult, isSubResult = false) => {
|
2020-12-30 22:13:19 +02:00
|
|
|
console.log('benchmarked: ' + result.name);
|
2022-03-21 23:29:00 +02:00
|
|
|
|
|
|
|
const fileSize = (size: number): string => {
|
|
|
|
const postFixes = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
|
|
let index = 0;
|
|
|
|
while (size > 1000 && index < postFixes.length - 1) {
|
|
|
|
size /= 1000;
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
return size.toFixed(2) + postFixes[index];
|
|
|
|
};
|
2019-01-27 01:03:40 +02:00
|
|
|
let details = '-';
|
|
|
|
if (result.items) {
|
2022-03-21 23:29:00 +02:00
|
|
|
details = 'items: ' + result.items.length +
|
|
|
|
', size: ' + fileSize(JSON.stringify(result.items).length);
|
2019-01-27 01:03:40 +02:00
|
|
|
}
|
2020-12-30 22:13:19 +02:00
|
|
|
if (result.contentWrapper) {
|
|
|
|
if (result.contentWrapper.directory) {
|
|
|
|
details = 'media: ' + result.contentWrapper.directory.media.length +
|
2022-03-21 23:29:00 +02:00
|
|
|
', directories: ' + result.contentWrapper.directory.directories.length +
|
2022-06-24 18:05:45 +02:00
|
|
|
', size: ' + fileSize(JSON.stringify(DirectoryDTOUtils.removeReferences(result.contentWrapper.directory)).length);
|
2020-12-30 22:13:19 +02:00
|
|
|
} else {
|
|
|
|
details = 'media: ' + result.contentWrapper.searchResult.media.length +
|
2022-03-21 23:29:00 +02:00
|
|
|
', directories: ' + result.contentWrapper.searchResult.directories.length +
|
|
|
|
', size: ' + fileSize(JSON.stringify(result.contentWrapper.searchResult).length);
|
|
|
|
|
2020-12-30 22:13:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isSubResult) {
|
2020-12-31 13:35:28 +02:00
|
|
|
printLine('| | ' + result.name + ' | ' + (result.duration).toFixed(1) + ' ms | ' + details + ' |');
|
2020-12-30 22:13:19 +02:00
|
|
|
} else {
|
2021-05-13 09:56:36 +02:00
|
|
|
printLine('| **' + (result.experiment ? '`[' + result.experiment + ']`' : '') + result.name + '** | | **' + (result.duration).toFixed(1) + ' ms** | **' + details + '** |');
|
2020-12-30 22:13:19 +02:00
|
|
|
}
|
|
|
|
if (result.subBenchmarks && result.subBenchmarks.length > 1) {
|
2021-04-18 15:48:35 +02:00
|
|
|
for (const item of result.subBenchmarks) {
|
2021-05-13 09:56:36 +02:00
|
|
|
printExperimentResult(item, true);
|
2020-12-30 22:13:19 +02:00
|
|
|
}
|
2019-01-27 01:03:40 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-05-13 09:56:36 +02:00
|
|
|
|
|
|
|
const printResult = (results: BenchmarkResult[]) => {
|
|
|
|
for (const result of results) {
|
|
|
|
printExperimentResult(result);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-01-27 01:03:40 +02:00
|
|
|
const run = async () => {
|
2020-12-30 22:13:19 +02:00
|
|
|
console.log('Running, RUNS:' + RUNS);
|
2019-01-27 01:28:04 +02:00
|
|
|
const start = Date.now();
|
2020-12-30 22:13:19 +02:00
|
|
|
const bm = new BenchmarkRunner(RUNS);
|
2019-01-27 01:03:40 +02:00
|
|
|
|
|
|
|
// header
|
2020-12-30 22:54:07 +02:00
|
|
|
await printHeader(await bm.getStatistic());
|
2019-01-27 01:03:40 +02:00
|
|
|
printTableHeader();
|
2021-05-13 09:56:36 +02:00
|
|
|
if (BMConfig.Benchmarks.bmScanDirectory) {
|
|
|
|
printResult(await bm.bmScanDirectory());
|
|
|
|
}
|
|
|
|
if (BMConfig.Benchmarks.bmSaveDirectory) {
|
|
|
|
printResult(await bm.bmSaveDirectory());
|
|
|
|
}
|
2020-12-30 22:13:19 +02:00
|
|
|
|
2021-05-13 09:56:36 +02:00
|
|
|
if (BMConfig.Benchmarks.bmListDirectory) {
|
|
|
|
printResult(await bm.bmListDirectory());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BMConfig.Benchmarks.bmListPersons) {
|
|
|
|
printResult(await bm.bmListPersons());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BMConfig.Benchmarks.bmAllSearch) {
|
|
|
|
(await bm.bmAllSearch()).forEach(res => printResult(res.result));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BMConfig.Benchmarks.bmAutocomplete) {
|
|
|
|
printResult(await bm.bmAutocomplete('a'));
|
|
|
|
}
|
2020-12-30 22:13:19 +02:00
|
|
|
printLine('*Measurements run ' + RUNS + ' times and an average was calculated.');
|
2019-01-27 01:03:40 +02:00
|
|
|
console.log(resultsText);
|
2019-01-27 01:28:04 +02:00
|
|
|
console.log('run for : ' + ((Date.now() - start)).toFixed(1) + 'ms');
|
2019-01-27 01:03:40 +02:00
|
|
|
};
|
|
|
|
|
2020-12-30 22:13:19 +02:00
|
|
|
run().then(console.log).catch(console.error);
|
2019-01-27 01:03:40 +02:00
|
|
|
|