---
title: "Discussion on \"Measuring Execution Time Safely with Monotonic Clocks\" | Hashnode"
description: "Discussion on \"Measuring Execution Time Safely with Monotonic Clocks\". Fix negative execution times caused by NTP clock syncs. Learn how to use monotonic clocks like performance.now() and System.nanoTime() correctly."
url: "https://hashnode.com/posts/measuring-execution-time-with-monotonic-clocks/6ade75962e03004eeacdfbb7"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Measuring Execution Time Safely with Monotonic Clocks](https://doogal.dev/measuring-execution-time-with-monotonic-clocks?utm_source=hashnode&utm_medium=feed)

Fix negative execution times caused by NTP clock syncs. Learn how to use monotonic clocks like performance.now() and System.nanoTime() correctly.

Oct 25 · 4 min read · doogal.dev  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#java](https://hashnode.com/tag/java)
-   [#performance](https://hashnode.com/tag/performance)
-   [#softwareengineering](https://hashnode.com/tag/softwareengineering)

## Written by

[Doogal Simpson](https://hashnode.com/@doogal)

@doogal

  
[View profile](https://hashnode.com/@doogal)

"hey doogal, what is .... ?"

## Responses 1

Markdown supported · ⌘↵ to post

[SMTasker](https://hashnode.com/@smtasker)

[Oct 29](https://hashnode.com/posts/measuring-execution-time-with-monotonic-clocks/6ade75962e03004eeacdfbb7/comment/6ae35415e5d6eb2076a9f5fe)

For a background worker, I would keep two fields in the log: started\_at\_utc for correlating events across services, and elapsed\_ms measured with a monotonic source inside the worker. A restart should start a new interval rather than reuse a saved raw monotonic reading. That keeps calendar scheduling and duration measurement explicit instead of mixing them in one timestamp.
