Cloudflare workers: how do I measure execution time of my method?


I’m trying to measure how long does it take for worker to handle user request and couldn’t find API that could do it correctly.

Things I’ve tried so far:

Result either 0 or undefined. Please share recipe


Since it is too quick it could be 0.

const requestStartTime =;
// your code
const executionTime = - requestStartTime
1 Like

Hi @natasignal,

We lock and console.time() to the time of last I/O, and we don’t implement, so it is not directly possible to measure CPU timing from within a script. This is necessary in order to mitigate timing side channel attacks (e.g., Spectre).

This means that you can measure I/O times – how long it takes to fetch() a resource, for example – but not things like how long a CPU-bound function takes to execute.



Is it possible that the server-timing header could be added? See

Currently I’m calculating this myself using the difference between before and after, but this is not reliable like you say.

It’s hard to know if you‘re hitting the limit in your worker. Does the worker have a hard limit on execution time?

1 Like

I feel like CPU time is the elephant in the room, if this cannot be provided it’s going to repeat and repeat in this forum forever. It’s ok if we can’t get it within the worker, but can we at least get an estimated CPU time in the response headers?

This way we can at least trial-and-error functions to find out what is consuming CPU-time.

closed #6

This topic was automatically closed after 30 days. New replies are no longer allowed.