Measure execution time
This commit is contained in:
parent
824852fe7a
commit
1b4bb1d2e2
@ -1,6 +1,7 @@
|
||||
// place files you want to import through the `$lib` alias in this folder.
|
||||
import path from 'path';
|
||||
import bunyan from 'bunyan';
|
||||
import type { MaybePromise } from '@sveltejs/kit';
|
||||
|
||||
export const log = bunyan.createLogger({
|
||||
name: 'fotochallenge',
|
||||
@ -29,3 +30,13 @@ if (!('STORAGE_PATH' in process.env)) {
|
||||
export const storagePath: string = process.env.STORAGE_PATH ?? defaultPath;
|
||||
|
||||
export default safePath;
|
||||
|
||||
export async function timedExecution<T>(
|
||||
fn: () => MaybePromise<T>
|
||||
): Promise<{ executionTime: number; result: T }> {
|
||||
const start = process.hrtime();
|
||||
const result = await fn();
|
||||
const end = process.hrtime(start);
|
||||
const executionTime = (end[0] * 1e6 + end[1]) / 1e6;
|
||||
return { executionTime, result };
|
||||
}
|
||||
|
Reference in New Issue
Block a user