2019-12-10 17:44:35 +08:00
|
|
|
import {Config} from '../src/common/config/private/Config';
|
|
|
|
import {ProjectPath} from '../src/backend/ProjectPath';
|
2020-12-31 04:13:19 +08:00
|
|
|
import {BenchmarkResult, BenchmarkRunner} from './BenchmarkRunner';
|
2019-12-10 17:44:35 +08:00
|
|
|
import {SearchTypes} from '../src/common/entities/AutoCompleteItem';
|
|
|
|
import {Utils} from '../src/common/Utils';
|
|
|
|
import {DiskMangerWorker} from '../src/backend/model/threading/DiskMangerWorker';
|
2020-12-29 05:08:57 +08:00
|
|
|
import {BMConfig} from './BMConfig';
|
|
|
|
import {GalleryManager} from '../src/backend/model/database/sql/GalleryManager';
|
2020-12-31 04:13:19 +08:00
|
|
|
import {PersonManager} from '../src/backend/model/database/sql/PersonManager';
|
2019-01-27 07:03:40 +08:00
|
|
|
|
2020-12-29 05:08:57 +08:00
|
|
|
|
|
|
|
Config.Server.Media.folder = BMConfig.path;
|
2019-01-27 07:03:40 +08:00
|
|
|
ProjectPath.reset();
|
2020-12-31 04:13:19 +08:00
|
|
|
const RUNS = BMConfig.RUNS;
|
2019-01-27 07:03:40 +08:00
|
|
|
|
|
|
|
let resultsText = '';
|
|
|
|
const printLine = (text: string) => {
|
|
|
|
resultsText += text + '\n';
|
|
|
|
};
|
|
|
|
|
|
|
|
const printHeader = async () => {
|
|
|
|
const dt = new Date();
|
|
|
|
printLine('## PiGallery2 v' + require('./../package.json').version +
|
2019-01-27 12:47:43 +08:00
|
|
|
', ' + Utils.zeroPrefix(dt.getDate(), 2) +
|
2019-01-27 07:03:40 +08:00
|
|
|
'.' + Utils.zeroPrefix(dt.getMonth() + 1, 2) +
|
|
|
|
'.' + dt.getFullYear());
|
2020-12-29 05:08:57 +08:00
|
|
|
printLine('**System**: ' + BMConfig.system);
|
2019-01-27 07:03:40 +08:00
|
|
|
const dir = await DiskMangerWorker.scanDirectory('./');
|
2020-12-29 05:08:57 +08:00
|
|
|
const gm = new GalleryManager();
|
2020-12-31 04:13:19 +08:00
|
|
|
const pm = new PersonManager();
|
|
|
|
printLine('\n**Gallery**: directories: ' +
|
2019-01-27 07:28:04 +08:00
|
|
|
dir.directories.length +
|
|
|
|
' media: ' + dir.media.length +
|
|
|
|
// @ts-ignore
|
2020-12-31 04:13:19 +08:00
|
|
|
', all persons: ' + dir.media.reduce((p, c) => p + (c.metadata.faces || []).length, 0) +
|
|
|
|
',unique persons (faces): ' + (await pm.getAll()).length + '\n');
|
2019-01-27 07:03:40 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const printTableHeader = () => {
|
2020-12-31 04:13:19 +08:00
|
|
|
printLine('| Action | Sub action | Action details | Average Duration | Details |');
|
|
|
|
printLine('|:------:|:----------:|:--------------:|:----------------:|:-------:|');
|
2019-01-27 07:03:40 +08:00
|
|
|
};
|
2020-12-31 04:13:19 +08:00
|
|
|
const printResult = (result: BenchmarkResult, actionDetails: string = '', isSubResult = false) => {
|
|
|
|
console.log('benchmarked: ' + result.name);
|
2019-01-27 07:03:40 +08:00
|
|
|
let details = '-';
|
|
|
|
if (result.items) {
|
|
|
|
details = 'items: ' + result.items;
|
|
|
|
}
|
2020-12-31 04:13:19 +08:00
|
|
|
if (result.contentWrapper) {
|
|
|
|
if (result.contentWrapper.directory) {
|
|
|
|
details = 'media: ' + result.contentWrapper.directory.media.length +
|
|
|
|
', directories:' + result.contentWrapper.directory.directories.length;
|
|
|
|
} else {
|
|
|
|
details = 'media: ' + result.contentWrapper.searchResult.media.length +
|
|
|
|
', directories:' + result.contentWrapper.searchResult.directories.length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isSubResult) {
|
|
|
|
printLine('| | ' + result.name + ' | ' + actionDetails +
|
|
|
|
' | ' + (result.duration).toFixed(1) + ' ms | ' + details + ' |');
|
|
|
|
} else {
|
|
|
|
printLine('| **' + result.name + '** | | ' + actionDetails +
|
|
|
|
' | ' + (result.duration).toFixed(1) + ' ms | ' + details + ' |');
|
|
|
|
}
|
|
|
|
if (result.subBenchmarks && result.subBenchmarks.length > 1) {
|
|
|
|
for (let i = 0; i < result.subBenchmarks.length; i++) {
|
|
|
|
printResult(result.subBenchmarks[i], '', true);
|
|
|
|
}
|
2019-01-27 07:03:40 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const run = async () => {
|
2020-12-31 04:13:19 +08:00
|
|
|
console.log('Running, RUNS:' + RUNS);
|
2019-01-27 07:28:04 +08:00
|
|
|
const start = Date.now();
|
2020-12-31 04:13:19 +08:00
|
|
|
const bm = new BenchmarkRunner(RUNS);
|
2019-01-27 07:03:40 +08:00
|
|
|
|
|
|
|
// header
|
|
|
|
await printHeader();
|
|
|
|
printTableHeader();
|
2020-12-31 04:13:19 +08:00
|
|
|
|
|
|
|
printResult(await bm.bmScanDirectory());
|
|
|
|
printResult(await bm.bmSaveDirectory());
|
|
|
|
printResult(await bm.bmListDirectory());
|
|
|
|
printResult(await bm.bmListPersons());
|
2019-01-27 07:03:40 +08:00
|
|
|
(await bm.bmAllSearch('a')).forEach(res => {
|
|
|
|
if (res.searchType !== null) {
|
2020-12-31 04:13:19 +08:00
|
|
|
printResult(res.result, '`a` as `' + SearchTypes[res.searchType] + '`');
|
2019-01-27 07:03:40 +08:00
|
|
|
} else {
|
2020-12-31 04:13:19 +08:00
|
|
|
printResult(res.result, '`a` as `any`');
|
2019-01-27 07:03:40 +08:00
|
|
|
}
|
|
|
|
});
|
2020-12-31 04:13:19 +08:00
|
|
|
printResult(await bm.bmInstantSearch('a'), '`a`');
|
|
|
|
printResult(await bm.bmAutocomplete('a'), '`a`');
|
|
|
|
printLine('*Measurements run ' + RUNS + ' times and an average was calculated.');
|
2019-01-27 07:03:40 +08:00
|
|
|
console.log(resultsText);
|
2019-01-27 07:28:04 +08:00
|
|
|
console.log('run for : ' + ((Date.now() - start)).toFixed(1) + 'ms');
|
2019-01-27 07:03:40 +08:00
|
|
|
};
|
|
|
|
|
2020-12-31 04:13:19 +08:00
|
|
|
run().then(console.log).catch(console.error);
|
2019-01-27 07:03:40 +08:00
|
|
|
|