diff --git a/src/lib/index.ts b/src/lib/index.ts index fe1270a..3106804 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -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( + fn: () => MaybePromise +): 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 }; +}