1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2024-12-12 11:15:22 +02:00
pigallery2/benchmark/index.ts

78 lines
2.7 KiB
TypeScript
Raw Normal View History

2019-12-10 11:44:35 +02:00
import {Config} from '../src/common/config/private/Config';
2019-01-27 01:03:40 +02:00
import * as path from 'path';
2019-12-10 11:44:35 +02:00
import {ProjectPath} from '../src/backend/ProjectPath';
2019-01-27 01:03:40 +02:00
import {BenchmarkResult, Benchmarks} from './Benchmarks';
2019-12-10 11:44:35 +02:00
import {SearchTypes} from '../src/common/entities/AutoCompleteItem';
import {Utils} from '../src/common/Utils';
import {DiskMangerWorker} from '../src/backend/model/threading/DiskMangerWorker';
2019-01-27 01:03:40 +02:00
const config: { path: string, system: string } = require(path.join(__dirname, 'config.json'));
Config.Server.Media.folder = config.path;
2019-12-29 10:34:08 +02:00
const dbFolder = __dirname;
2019-01-27 01:03:40 +02:00
ProjectPath.reset();
2019-01-27 01:28:04 +02:00
const RUNS = 50;
2019-01-27 01:03:40 +02: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 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());
printLine('**System**: ' + config.system);
const dir = await DiskMangerWorker.scanDirectory('./');
2019-01-27 01:28:04 +02:00
printLine('**Gallery**: directories: ' +
dir.directories.length +
' media: ' + dir.media.length +
// @ts-ignore
', faces: ' + dir.media.reduce((p, c) => p + (c.metadata.faces || []).length, 0));
2019-01-27 01:03:40 +02:00
};
const printTableHeader = () => {
printLine('| action | action details | average time | details |');
printLine('|:------:|:--------------:|:------------:|:-------:|');
};
const printResult = (result: BenchmarkResult, action: string, actionDetails: string = '') => {
2019-01-27 01:28:04 +02:00
console.log('benchmarked: ' + action);
2019-01-27 01:03:40 +02:00
let details = '-';
if (result.items) {
details = 'items: ' + result.items;
}
if (result.media) {
details = 'media: ' + result.media + ', directories:' + result.directories;
}
printLine('| ' + action + ' | ' + actionDetails +
2019-01-27 01:28:04 +02:00
' | ' + (result.duration).toFixed(1) + 'ms | ' + details + ' |');
2019-01-27 01:03:40 +02:00
};
const run = async () => {
2019-01-27 01:28:04 +02:00
const start = Date.now();
2019-12-29 10:34:08 +02:00
const bm = new Benchmarks(RUNS, dbFolder);
2019-01-27 01:03:40 +02:00
// header
await printHeader();
printTableHeader();
printResult(await bm.bmScanDirectory(), 'Scanning directory');
printResult(await bm.bmSaveDirectory(), 'Saving directory');
printResult(await bm.bmListDirectory(), 'Listing Directory');
(await bm.bmAllSearch('a')).forEach(res => {
if (res.searchType !== null) {
printResult(res.result, 'searching', '`a` as `' + SearchTypes[res.searchType] + '`');
} else {
printResult(res.result, 'searching', '`a` as `any`');
}
});
printResult(await bm.bmInstantSearch('a'), 'instant search', '`a`');
printResult(await bm.bmAutocomplete('a'), 'auto complete', '`a`');
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
};
run();