Skip to content

Repository files navigation

perf-fn

Measure async and sync function execution time using the Performance API

Install

npm install perf-fn

Usage

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

About

Measure async and sync function execution time using the Performance API

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages