The time Library

Contents[Show]

A blog, dealing with multithreading in modern C++ but not writing about the new time library is not complete. Especially, because I often used the time library in my posts to measure the performance of shortcode snippets. Therefore, I give in this post an overview of the components of the time library: time point, time duration, and clock. I will write in additional posts about each of these three components.

As ever before the practice is the theory.

Timepoint, time duration and clock

The time library consists of three parts which are dependent on each other.

• Timepoint: The time point is given by its starting point - the so-called epoch - and the time duration which refers to the epoch.
• Time duration: The time duration is the difference between two-time points. It's measured in the number of time ticks.
• Clock: The clock consists of a starting point and a time tick. This information enables you to calculate the current time.

You can compare time points. When you add a time duration to a time point you get a new time point. The time tick is the accuracy of the clock in which you measure the time duration. The birth of Christ is my culture the starting time point and a year a typically time tick.

I will use the three concepts to present the lifetime of the 2011 dead father of the programming language C:  Dennis Ritchie. For simplicity reasons, I'm only interested in the years.

The time points 1941 and 2011 are defined by the birth of Christ and the time duration. Therefore, the birth of Christ is our epoch. Of course, the epoch is also a time point. When I subtract 1941 from 2011 I get the time duration. This dime duration is measured with the accuracy year. Dennis Ritchie became 70 years old.

Before I dive deeper into the time library in an upcoming post a few remarks. A time point consists of a clock and a time duration. C++ has the clocks std::chrono::system_clock, std::chrono::steady_clock, and std::chrono::high_resolution_clock. The time duration can be positive and negative. The known time durations as std::chrono::seconds, std::chrono::minutes or std::chrono::hours are predefined in C++. Additionally, C++4 offers time literals: For example 1s, 1min or 1h. The clocks differ in their accuracy (time tick) and epoch. Although it's not defined but usually std::chrono::system_clock starts at 1.1.1970. Each clock has a method now for returning the current time (time point).

What's next?

I the next post I will write about the concept time point. Therefore, I will calculate in different time ticks how much time is passed since 1.1.1970.

Thanks a lot to my Patreon Supporters: Matt Braun, Roman Postanciuc, Tobias Zindl, Marko, G Prvulovic, Reinhold Dröge, Abernitzke, Frank Grimm, Sakib, Broeserl, António Pina, Sergey Agafyin, Андрей Бурмистров, Jake, GS, Lawton Shoemake, Animus24, Jozo Leko, John Breland, espkk, Louis St-Amour, Venkat Nandam, Jose Francisco, Douglas Tinkham, Kuchlong Kuchlong, Robert Blanch, Truels Wissneth, Kris Kafka, Mario Luoni, Neil Wang, Friedrich Huber, lennonli, Pramod Tikare Muralidhara, Peter Ware, Tobi Heideman, Daniel Hufschläger, Red Trip, Alexander Schwarz, Tornike Porchxidze, Alessandro Pezzato, Evangelos Denaxas, Bob Perry, Satish Vangipuram, Andi Ireland, Richard Ohnemus, Michael Dunsky, Dimitrov Tsvetomir, Leo Goodstadt, Eduardo Velasquez, John Wiederhirn, and Yacob Cohen-Arazi.

Thanks in particular to Jon Hess, Lakshman, Christian Wittenhorst, Sherhy Pyton, Dendi Suhubdy, Sudhakar Belagurusamy, Richard Sargeant, Rusty Fleming, and Said Mert Turkal.

Seminars

I'm happy to give online seminars or face-to-face seminars worldwide. Please call me if you have any questions.

Standard Seminars (English/German)

Here is a compilation of my standard seminars. These seminars are only meant to give you a first orientation.

Modernes C++,

Tags: time

0 #1 ดูแลผู้สูงอายุ 2016-10-20 10:51
I've been surfing online more than three hours today, yet I
never found any interesting article like yours. It is pretty worth enough for me.
Personally, if all webmasters and bloggers made good content as you
did, the internet will be much more useful than ever before.

Subscribe to the newsletter (+ pdf bundle)

 Name Email Please enable the javascript to submit this form

Visitors

Today 4516

Yesterday 8323

Week 37396

Month 110806

All 7173096

Currently are 198 guests and no members online

• The First Big Update of My C++20 Book

Love your book. Just wondering if you have errata for the book?

• C++20: An Infinite Data Stream with Coroutines

FYI, final_suspend needs to be noexcept ;-)

• C++20: Pythonic with the Ranges Library

I thought the most important part of ranges / views is their laziness. If so, this is not a great ...

• Cooperative Interruption of a Thread in C++20

The counter variable should be atomic because the callback is invoked from the main thread; otherwise ...

• Template Instantiation

That's assuming `make` is installed, though I have never seen a non-Windows system without it. It ...