diff --git a/benchmark/Benchmark.ts b/benchmark/Benchmark.ts index 1eec33b7..c01d9050 100644 --- a/benchmark/Benchmark.ts +++ b/benchmark/Benchmark.ts @@ -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, }; } diff --git a/benchmark/BenchmarkRunner.ts b/benchmark/BenchmarkRunner.ts index 352c4920..b5da92e7 100644 --- a/benchmark/BenchmarkRunner.ts +++ b/benchmark/BenchmarkRunner.ts @@ -37,7 +37,7 @@ export interface BenchmarkResult { experiment?: string; duration: number; contentWrapper?: ContentWrapper; - items?: number; + items?: any[]; subBenchmarks?: BenchmarkResult[]; } diff --git a/benchmark/Experiments.ts b/benchmark/Experiments.ts index 4bfa5b7f..31b68009 100644 --- a/benchmark/Experiments.ts +++ b/benchmark/Experiments.ts @@ -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 } = {}; diff --git a/benchmark/index.ts b/benchmark/index.ts index a6f0c014..aa14898c 100644 --- a/benchmark/index.ts +++ b/benchmark/index.ts @@ -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) { diff --git a/src/backend/middlewares/ServerTimingMWs.ts b/src/backend/middlewares/ServerTimingMWs.ts index e40ae26b..51cbc7cc 100644 --- a/src/backend/middlewares/ServerTimingMWs.ts +++ b/src/backend/middlewares/ServerTimingMWs.ts @@ -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); + }; };