From 0748a3ed5b4ba38812cebf0e8577e5b88d4c7cc9 Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Sat, 26 Jan 2019 18:28:04 -0500 Subject: [PATCH] adding performance benchmark --- benchmark/Benchmarks.ts | 6 +++--- benchmark/README.md | 19 ++++++++++++++++++- benchmark/index.ts | 13 ++++++++++--- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/benchmark/Benchmarks.ts b/benchmark/Benchmarks.ts index 58b34e8e..6fe04112 100644 --- a/benchmark/Benchmarks.ts +++ b/benchmark/Benchmarks.ts @@ -84,18 +84,18 @@ export class Benchmarks { const startSkip = process.hrtime(); await beforeEach(); const endSkip = process.hrtime(startSkip); - skip += (endSkip[0] * 1000 + endSkip[1] / 1000); + skip += (endSkip[0] * 1000 + endSkip[1] / 1000000); } await fn(); if (afterEach) { const startSkip = process.hrtime(); await afterEach(); const endSkip = process.hrtime(startSkip); - skip += (endSkip[0] * 1000 + endSkip[1] / 1000); + skip += (endSkip[0] * 1000 + endSkip[1] / 1000000); } } const end = process.hrtime(start); - const duration = (end[0] * 1000 + end[1] / 1000) / this.RUNS; + const duration = (end[0] * 1000 + end[1] / 1000000) / this.RUNS; if (!scanned) { return { diff --git a/benchmark/README.md b/benchmark/README.md index 9ace280d..e2491173 100644 --- a/benchmark/README.md +++ b/benchmark/README.md @@ -2,4 +2,21 @@ These results are created mostly for development, but I'm making them public for curious users. - +## PiGallery2 v1.5.8, 06.01.2019 + +**System**: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz, 16GB Ram, SHDD: 1TB, 5400 rpm +**Gallery**: directories: 0 media: 341, faces: 39 +| action | action details | average time | details | +|:------:|:--------------:|:------------:|:-------:| +| Scanning directory | | 2486.5ms | media: 341, directories:0 | +| Saving directory | | 780.0ms | - | +| Listing Directory | | 31.5ms | media: 341, directories:0 | +| searching | `a` as `directory` | 2.9ms | - | +| searching | `a` as `person` | 7.3ms | media: 39, directories:0 | +| searching | `a` as `keyword` | 30.8ms | media: 339, directories:0 | +| searching | `a` as `position` | 25.7ms | media: 282, directories:0 | +| searching | `a` as `photo` | 2.8ms | - | +| searching | `a` as `video` | 2.6ms | - | +| searching | `a` as `any` | 33.0ms | media: 339, directories:0 | +| instant search | `a` | 6.1ms | media: 10, directories:0 | +| auto complete | `a` | 5.4ms | items: 10 | diff --git a/benchmark/index.ts b/benchmark/index.ts index 98a6048a..9a1b975d 100644 --- a/benchmark/index.ts +++ b/benchmark/index.ts @@ -10,7 +10,7 @@ const config: { path: string, system: string } = require(path.join(__dirname, 'c Config.Server.imagesFolder = config.path; const dbPath = path.join(__dirname, 'test.db'); ProjectPath.reset(); -const RUNS = 1; +const RUNS = 50; let resultsText = ''; const printLine = (text: string) => { @@ -25,7 +25,11 @@ const printHeader = async () => { '.' + dt.getFullYear()); printLine('**System**: ' + config.system); const dir = await DiskMangerWorker.scanDirectory('./'); - printLine('**Gallery**: directories:' + dir.directories.length + ' media:' + dir.media.length); + printLine('**Gallery**: directories: ' + + dir.directories.length + + ' media: ' + dir.media.length + + // @ts-ignore + ', faces: ' + dir.media.reduce((p, c) => p + (c.metadata.faces || []).length, 0)); }; @@ -34,6 +38,7 @@ const printTableHeader = () => { printLine('|:------:|:--------------:|:------------:|:-------:|'); }; const printResult = (result: BenchmarkResult, action: string, actionDetails: string = '') => { + console.log('benchmarked: ' + action); let details = '-'; if (result.items) { details = 'items: ' + result.items; @@ -42,10 +47,11 @@ const printResult = (result: BenchmarkResult, action: string, actionDetails: str details = 'media: ' + result.media + ', directories:' + result.directories; } printLine('| ' + action + ' | ' + actionDetails + - ' | ' + (result.duration / 1000).toFixed(2) + 's | ' + details + ' |'); + ' | ' + (result.duration).toFixed(1) + 'ms | ' + details + ' |'); }; const run = async () => { + const start = Date.now(); const bm = new Benchmarks(RUNS, dbPath); // header @@ -64,6 +70,7 @@ const run = async () => { printResult(await bm.bmInstantSearch('a'), 'instant search', '`a`'); printResult(await bm.bmAutocomplete('a'), 'auto complete', '`a`'); console.log(resultsText); + console.log('run for : ' + ((Date.now() - start)).toFixed(1) + 'ms'); }; run();