Skip to content
Home · Sonraki hedefe 100 XP
Son hareketler
Henüz bir öğrenme hareketi yok. İlk derse başlayın.

Programming Fundamentals

C++ time: Wall clock and time measurement

Recording the calendar time of an event and measuring the elapsed time are two different things. The system time can be corrected; Therefore, a monotonic clock should be preferred for time measurement.

Bu derste neler var?

SIBERSALDIRI.COM · FOCUSED LESSON

What you will learn

  • To explain the relationship between clock selection and time difference.
  • “Why is steady_clock appropriate for duration rather than timestamp?” To give a reasoned answer to the question.
  • Changing the example and comparing expected and observed behavior.

How it works and where the trust boundary lies

steady_clock corresponds to time comparison, system_clock corresponds to real-world time records. Keep volumes open with chrono duration types. Do not directly mix time_point values ​​of different clocks. The time period and display is a separate presentation decision from the stored time point.

C++ time: Wall clock and time measurement flow: Clock selection → Time difference → Explicit unit
Time selection → Time difference → Open unit. The diagram shows the relationship; It does not replace the entire application.

Worked example

The following passage makes the concept visible. Evaluate samples containing commands or code in your own separate testing environment, not in the production system. Architectural diagrams and policy examples are not executable programs.

#include <chrono>
#include <iostream>
int main(){
 auto start=std::chrono::steady_clock::now();
 auto end=std::chrono::steady_clock::now();
 std::cout<<std::chrono::duration_cast<std::chrono::microseconds>(end-start).count();
}

Expected result and interpretation

The short time between two measurements is displayed in microseconds; It is possible to get zero.

Compare the scenarios

StatusRecommended approachWhy?
elapsed timesteady_clockMonotonous hour is suitable
calendar entrysystem_clockIt is related to real time
Unit conversionOpen durationScale does not interfere

Practice task

Enlarge the measured operation and make the unit conversion to milliseconds. Don't judge performance based on a single measurement.

  1. Write down the expected outcome and acceptance condition before the action.
  2. Change a single variable; Record the observation and the medium you used.
  3. Evaluate the result with the comparison table above. Explain which assumption might be wrong if it does not fit.

Common mistake and how to correct it

Do not ignore the calendar clock going back when measuring the time.

Test your understanding

Why is steady_clock appropriate for duration rather than timestamp?

Answer explained: Monotonic progress assurance separates time accounting from clock corrections; It is not designed for calendar display.

Continue with related lessons

Technical reference

The explanation and examples of this course have been re-prepared for the academy. The link below is a technical reference to verify details of the technology or security approach used.

Bir adım daha ilerlediniz.

Dersi bitirdiyseniz tamamlandı olarak işaretleyin. İlerlemeniz bu cihazda saklanır.

Academy menu

Akademide ara

En az 2 karakter yazın.