perf-fn
v1.0.0
Published
Measure async and sync function execution time using the Performance API
Maintainers
Readme
perf-fn
Measure async and sync function execution time using the Performance API
Install
npm install perf-fnUsage
import 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"}'));API
perfFn(function_)
Returns a Promise<{result, duration}> where duration is in milliseconds.
function_
Type: () => T | Promise<T>
The async or sync function to measure.
perfFnSync(function_)
Returns {result, duration} where duration is in milliseconds.
function_
Type: () => T
The sync function to measure.
Related
- abort-timer - Create an AbortSignal that aborts after a timeout
License
MIT
