MediumChronolap: The Next Generation Stopwatch for .NET Applications | by Ertugrul Kara | The Syntax Hub | Medium
Sitemap
The Syntax Hub

Tired of dry coding tutorials? We see code as a canvas for creation. Join us to explore unique projects, turn ideas into digital reality, and master the art of development. Subscribe to start painting with code!

Chronolap: The Next Generation Stopwatch for .NET Applications

--

Press enter or click to view image in full size
Photo by Sabri Tuzcu on Unsplash

In .NET, the Stopwatch class is one of the most commonly used tools for measuring the duration of operations. However, it has a significant drawback: it does not support lap tracking.

In this article, I will share how I developed an alternative to the classic Stopwatch — a timer class called Chronolap, which supports both synchronous operation and lap tracking with logging capabilities.

🚩 Why Stopwatch Isn’t Enough

Great, clear, and easy to understand. But what if we wanted to measure multiple sections?

The NuGet package I published, “chronolap,” makes this very easy.

First, you need to add it to your project;

dotnet package add chronolap

Then, let’s use it in a project as an example;

Actually, the core functionality is this simple. However, usually people want to record these measurements as logs as well. For this, without any extra development, if you inject a Logger object that implements the ILogger interface, the measurements for each lap will be automatically logged.

Get Ertugrul Kara’s stories in your inbox

Join Medium for free to get updates from this writer.

Here is an example of that;

You can use any Logger class you want, whether it’s Console, Serilog, or another — it’s up to your creativity! :)

📚 Conclusion
The Stopwatch class in .NET may be sufficient for basic measurements. However, in real-world scenarios — especially in performance analysis or benchmarking tests — lap tracking can be a lifesaver.

For the code and example project;

👉 GitHub — ertugrulkra/chronolap

If you want, there is also a Python version available. If you have any questions I’m just an email away.

☕ Support the Project
If you like the project, you can support me with a coffee:

BuyMeACoffee.com/ertugrulkara

--

--

The Syntax Hub
The Syntax Hub

Published in The Syntax Hub

Tired of dry coding tutorials? We see code as a canvas for creation. Join us to explore unique projects, turn ideas into digital reality, and master the art of development. Subscribe to start painting with code!