Measure async and sync function execution time using the Performance API
npm install perf-fnimport perfFn, {perfFnSync} from 'perf-fn';
const {result, duration} = await perfFn(async () => {
const response = await fetch('https://example.com');
return response.status;
});
console.log(`Took ${duration}ms`);
const {result: data, duration: syncTime} = perfFnSync(() => JSON.parse('{"key": "value"}'));Returns a Promise<{result, duration}> where duration is in milliseconds.
Type: () => T | Promise<T>
The async or sync function to measure.
Returns {result, duration} where duration is in milliseconds.
Type: () => T
The sync function to measure.
- abort-timer - Create an AbortSignal that aborts after a timeout
MIT