Profiling Workers - same timstamp for start and end times

Hi,

am trying to achieve a very basic profiler by measuring difference in miliseconds in several different code execution points.

    start_time = Date.now()
<...>
     end_time = Date.now()
    diff_time = end_time - start_time

The values these variables get assigned are as follows:
Start time: 1569593739079 End time: 1569593739079 Diff time: 0 .

I would expect at least the minimall difference - what am I missing here?

Thanks!

I personally return this on the header when debugging.

It was mentioned in a previous discussion by Cloudflare that…
" Date.now() only advances when I/O is performed, however, and is intentionally coarse."

Which means that you can’t measure how long a worker takes to do some work, but you can measure how long requests using fetch take to complete. If i remember correctly, they also make exact timing harder to avoid timing attacks.

3 Likes