1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2024-11-28 08:58:49 +02:00

Updating benchmark to contain results size

This commit is contained in:
Patrik J. Braun 2022-03-21 22:29:00 +01:00
parent 56b0b38d93
commit 6394eb4f86
5 changed files with 27 additions and 14 deletions

View File

@ -153,7 +153,7 @@ export class Benchmark {
return {
name,
duration: null,
items: output.length,
items: output,
};
}
@ -170,7 +170,7 @@ export class Benchmark {
return {
name,
duration: null,
items: msg.length,
items: msg,
};
}

View File

@ -37,7 +37,7 @@ export interface BenchmarkResult {
experiment?: string;
duration: number;
contentWrapper?: ContentWrapper;
items?: number;
items?: any[];
subBenchmarks?: BenchmarkResult[];
}

View File

@ -1,10 +1,6 @@
export const Experiments = {
db: {
name: 'SQlite',
groups: {
betterSqlite: 'better-sqlite'
}
}
export const Experiments:
{ [key: string]: { name: string, groups: { [key: string]: string } } } = {
};
export const ActiveExperiments: { [key: string]: string } = {};

View File

@ -3,6 +3,7 @@ import {ProjectPath} from '../src/backend/ProjectPath';
import {BenchmarkResult, BenchmarkRunner} from './BenchmarkRunner';
import {Utils} from '../src/common/Utils';
import {BMConfig} from './BMConfig';
import {DirectoryDTOUtils} from '../src/common/entities/DirectoryDTO';
Config.Server.Media.folder = BMConfig.path;
@ -35,17 +36,31 @@ const printTableHeader = () => {
};
const printExperimentResult = (result: BenchmarkResult, isSubResult = false) => {
console.log('benchmarked: ' + result.name);
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];
};
let details = '-';
if (result.items) {
details = 'items: ' + result.items;
details = 'items: ' + result.items.length +
', size: ' + fileSize(JSON.stringify(result.items).length);
}
if (result.contentWrapper) {
if (result.contentWrapper.directory) {
details = 'media: ' + result.contentWrapper.directory.media.length +
', directories: ' + result.contentWrapper.directory.directories.length;
', directories: ' + result.contentWrapper.directory.directories.length +
', size: ' + fileSize(JSON.stringify(DirectoryDTOUtils.packDirectory(result.contentWrapper.directory)).length);
} else {
details = 'media: ' + result.contentWrapper.searchResult.media.length +
', directories: ' + result.contentWrapper.searchResult.directories.length;
', directories: ' + result.contentWrapper.searchResult.directories.length +
', size: ' + fileSize(JSON.stringify(result.contentWrapper.searchResult).length);
}
}
if (isSubResult) {

View File

@ -29,7 +29,7 @@ export const ServerTime = (id: string, name: string) => {
return;
}
const m = descriptor.value;
descriptor.value = (req: Request, res: Response, next: NextFunction) => {
const customAction = (req: Request, res: Response, next: NextFunction) => {
req.timing = req.timing || {};
req.timing[id] = new ServerTimeEntry(name);
req.timing[id].start();
@ -38,6 +38,8 @@ export const ServerTime = (id: string, name: string) => {
next(err);
});
};
descriptor.value = new Function('action', 'return function ' + m.name + '(...args){ action(...args) };')(customAction);
};
};