---
title: std::chrono ambiguities
description: std::chrono ambiguities
image: https://blog.quasar.ai/hubfs/IMG_8938-2.jpg
---

[![Quasar](https://blog.quasar.ai/hubfs/logo-1.svg?t=1538728673587)](https://quasardb.net/)

- [What is Quasar?](https://quasar.ai/what-is-quasar/)
- [Deployment & Pricing](https://quasar.ai/deployment-pricing/)
- [Blog & News](https://quasar.ai/blog-news/)
- Company 
    - [About us](https://quasar.ai/about/)
    - [Contact us](https://quasar.ai/contact/)

- [Support & Services](https://quasar.ai/support-services/)
- [Documentation](https://doc.quasardb.net/master/)

# Blog

# std::chrono ambiguities

Posted by [user](https://blog.quasar.ai/author/user) on 30 Jan 2015

- [Tweet](https://twitter.com/share)

Precision is costly - As you saw in our previous post getting a timestamp as precise as possible is expensive in precious cycles. We do it only when we really need it because we really care about writing the [world fastest database](https://www.quasardb.net/).

Fortunately, since C++ 11, [std::chrono](http://en.cppreference.com/w/cpp/chrono) will be happy to provide you with timestamps and a full set of timing routines and time related functions.

As you can see, three clocks are provided:

1. [system\_clock](http://en.cppreference.com/w/cpp/chrono/system_clock) (the system clock, quite precise in most implementations I’ve inspected);
2. [steady\_clock](http://en.cppreference.com/w/cpp/chrono/steady_clock) (a monotonic clock);
3. [high*resolution*clock](http://en.cppreference.com/w/cpp/chrono/high_resolution_clock) (the clock with the shortest tick period available).

Now, there are some catches:  high*resolution*clock isn’t necessarily more precise than system*clock (and may not be the most precise clock you can get on an OS) and [time](http://en.cppreference.com/w/cpp/chrono/time_point/time_since_epoch)*[since\_epoch()](http://en.cppreference.com/w/cpp/chrono/time_point/time_since_epoch) doesn’t do exactly what you think it does.

## On the actual precision

For example Visual Studio’s implementation is based on [GetSystemTimePreciseAsFileTime](https://msdn.microsoft.com/en-us/library/windows/desktop/hh706895(v=vs.85).aspx) (you’ve got to love Windows API functions name), which is quite precise but not as precise as Windows can be (it is insufficient for example for the use case of our high resolution timestamp).

That means that when using high*resolution*clock on Windows **you are getting the most precise clock of the STL implementation**, not the most precise clock of the OS.

If you need more precision, you need to use [QueryPerformanceCounter](https://msdn.microsoft.com/en-us/library/windows/desktop/ms644904(v=vs.85).aspx).

## On the result of time*since*epoch

If you, like me, don’t read carefully the documentation, you might believe that time*since*epoch returns an UNIX epoch of your time\_point. Let’s read  the documentation together:

> Return value: The amount of time between this time\_point and the clock's epoch

Let’s read it again:

> Return value: The amount of time between this time\_point and the **clock's** epoch

Not UNIX epoch, but the clock’s epoch, which in many cases is the UNIX epoch. Feeling lost?

I got bitten by this when discovering that the implementation of libc++ high*resolution*clock is the only (tested) implementation that isn’t based on UNIX epoch.

In order to have a proper UNIX epoch, you must use system*clock [to](http://en.cppreference.com/w/cpp/chrono/system_clock/to_time_t)*[time*t*](http://en.cppreference.com/w/cpp/chrono/system_clock/to_time_t)*, don’t assume time*since\_epoch is UNIX epoch, even if it is in your implementation.

 Topics: [c++](https://blog.quasar.ai/tag/c), [chrono](https://blog.quasar.ai/tag/chrono), [libc++](https://blog.quasar.ai/tag/libc), [stl](https://blog.quasar.ai/tag/stl), [Uncategorized](https://blog.quasar.ai/tag/uncategorized), [visual studio](https://blog.quasar.ai/tag/visual-studio)

- [![QuasarDB](https://blog.quasar.ai/hubfs/logo-1.svg?t=1539155681377)](https://quasardb.net/)

- [What is Quasar?](https://quasar.ai/what-is-quasar/)
- [Deployment & Pricing](https://quasar.ai/deployment-pricing/)
- [Blog & News](https://quasar.ai/blog-news/)

- [Support & Services](https://quasar.ai/support-services/)
- [Documentation](https://doc.quasardb.net/master/)

- [About Us](https://quasar.ai/about/)
- [Contact us](https://quasar.ai/contact/)

- <https://x.com/quasardb>
- <https://www.linkedin.com/company/quasardb>
- <https://github.com/bureau14>
- <https://www.youtube.com/channel/UCCX_fOqhKKYnJNfeMPVjiGA>

© Copyright 2026 QuasarDB. All rights reserved

- [Legal information](https://quasar.ai/legal-information/)
- [Privacy policy](https://quasar.ai/privacy-policy/)