개요 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
고정밀 시각, 시간측정용 std::chrono 는 "C++11" 이후 도입, Visual C++ 2012 이후 도입. 용어. 시각 : time point. 시간 : time interval, 2개 시각의 간격. 특징 - 고정밀(최소 시간단위 : 나노초), 편리기능 함수들. - 주요 클래스 : duration, time_point - 주요구조체 : system_clock, steady_clock - steady_clock 특징 Visual C++ 에서는 내부적으로 QueryPerformanceCounter 로 구현되어있음. monotonic. 늦게 호출된 now() 가 먼저 호출된 now() 이상의 값(같거나 더 큰 값)이 나온다는 의미. 헤더파일 #include <chrono> 더보기
<chrono>
Include the standard header <chrono> to define classes and functions that represent and manipulate time durations and time instants. (Visual Studio 2015:) The implementation of steady_clock has changed to meet the C++ Standard requirements for steadiness and monotonicity. steady_clock is now based on QueryPerformanceCounter() and high_resolution_clock is now a typedef for steady_clock. As a result, in Visual C++ steady_clock::time_point is now a typedef for chrono::time_point<steady_clock>; however, this is not necessarily the case for other implementations. C++
복사
|
operator "" h(unsigned long long Val) operator "" h(long double Val) | Specifies that the value represents hours. |
operator "" min(unsigned long long Val) operator "" min(long double Val) | Specifies that the value represents minutes. |
operator "" s(unsigned long long Val)operator "" s(long double Val) | Specifies that the value represents seconds. |
operator "" ms(unsigned long long Val)operator "" ms(long double Val) | Specifies that the value represents milliseconds. |
operator "" us(unsigned long long Val)operator "" us(long double Val) | Specifies that the value represents microseconds. |
operator "" ns(unsigned long long Val)operator "" ns(long double Val) | Specifies that the value represents nanoseconds. |
Classes
Name | Description |
---|---|
duration Class | Describes a type that holds a time interval. |
time_point Class | Describes a type that represents a point in time. |
Structs
Name | Description |
---|---|
common_type Structure | Describes specializations of template class common_type for instantiations of duration and time_point. |
duration_values Structure | Provides specific values for the duration template parameter Rep. |
steady_clock struct | Represents a steady clock. |
system_clock Structure | Represents a clock type that is based on the real-time clock of the system. |
treat_as_floating_point Structure | Specifies whether a type can be treated as a floating-point type. |
Functions
Name | Description |
---|---|
duration_cast Function | Casts a duration object to a specified type. |
time_point_cast Function | Casts a time_point object to a specified type. |
Operators
Name | Description |
---|---|
operator- Operator (STL) | Operator for subtraction or negation of duration and time_point objects. |
operator!= Operator (STL) | Inequality operator that is used with duration or time_point objects. |
operator modulo (STL) | Operator for modulo operations on duration objects. |
operator* Operator (STL) | Multiplication operator for duration objects. |
operator/ Operator (STL) | Division operator for duration objects. |
operator+ Operator (STL) | Adds duration and time_point objects. |
operator< Operator (STL) | Determines whether one duration or time_point object is less than another duration or time_point object. |
operator<= Operator (STL) | Determines whether one duration or time_point object is less than or equal to another duration or time_point object. |
operator== Operator (STL) | Determines whether two duration objects represent time intervals that have the same length, or whether two time_point objects represent the same point in time. |
operator> Operator (STL) | Determines whether one duration or time_point object is greater than another duration or time_point object. |
operator>= Operator (STL) | Determines whether one duration or time_point object is greater than or equal to another duration or time_point object. |
Predefined Duration Types
For more information about ratio types that are used in the following typedefs, see <ratio>.
Typedef | Description |
---|---|
typedef duration<long long, nano> nanoseconds; | Synonym for a duration type that has a tick period of one nanosecond. |
typedef duration<long long, micro> microseconds; | Synonym for a duration type that has a tick period of one microsecond. |
typedef duration<long long, milli> milliseconds; | Synonym for a duration type that has a tick period of one millisecond. |
typedef duration<long long> seconds; | Synonym for a duration type that has a tick period of one second. |
typedef duration<int, ratio<60> > minutes; | Synonym for a duration type that has a tick period of one minute. |
typedef duration<int, ratio<3600> > hours; | Synonym for a duration type that has a tick period of one hour. |
Literals
(C++11)The <chrono> header defines the following user-defined literals that you can use for greater convenience, type-safety and maintainability of your code. These literals are defined in the literals::chrono_literals inline namespace and are in scope when std::chrono is in scope.
Literal | Description |
---|---|
chrono::hours operator "" h(unsigned long long Val) | Specifies hours as an integral value. |
chrono::duration<double, ratio<3600> > operator "" h(long double Val) | Specifies hours as a floating-point value. |
chrono::minutes (operator "" min)(unsigned long long Val) | Specifies minutes as an integral value. |
chrono::duration<double, ratio<60> > (operator "" min)( long double Val) | Specifies minutes as a floating-point value. |
chrono::seconds operator "" s(unsigned long long Val) | Specifies minutes as an integral value. |
chrono::duration<double> operator "" s(long double Val) | Specifies seconds as a floating-point value. |
chrono::milliseconds operator "" ms(unsigned long long Val) | Specifies milliseconds as an integral value. |
chrono::duration<double, milli> operator "" ms(long double Val) | Specifies milliseconds as a floating-point value. |
chrono::microseconds operator "" us(unsigned long long Val) | Specifies microseconds as an integral value. |
chrono::duration<double, micro> operator "" us(long double Val) | Specifies microseconds as a floating-point value. |
chrono::nanoseconds operator "" ns(unsigned long long Val) | Specifies nanoseconds as an integral value. |
chrono::duration<double, nano> operator "" ns(long double Val) | Specifies nanoseconds as a floating-point value. |
from : MSDN
더보기
duration Class
Describes a type that holds a time interval, which is an elapsed time between two time points.
Describes a type that holds a time interval, which is an elapsed time between two time points.
복사
template< class Rep, class Period = ratio<1> > class duration; template< class Rep, class Period > class duration; template< class Rep, class Period1, class Period2 > class duration <duration<Rep, Period1>, Period2>;
The template argument Rep describes the type that is used to hold the number of clock ticks in the interval. The template argument Period is an instantiation of ratio that describes the size of the interval that each tick represents.
Public Typedefs
Name | Description |
---|---|
duration::period Typedef | Represents a synonym for the template parameter Period. |
duration::rep Typedef | Represents a synonym for the template parameter Rep. |
Public Constructors
Name | Description |
---|---|
duration::duration Constructor | Constructs a duration object. |
Public Methods
Name | Description |
---|---|
duration::count Method | Returns the number of clock ticks in the time interval. |
duration::max Method | Static. Returns the maximum allowable value of template parameter Ref. |
duration::min Method | Static. Returns the lowest allowable value of template parameter Ref. |
duration::zero Method | Static. In effect, returns Rep(0). |
Public Operators
Name | Description |
---|---|
duration::operator- Operator | Returns a copy of the duration object together with a negated tick count. |
duration::operator-- Operator | Decrements the stored tick count. |
duration::operator= Operator | Reduces the stored tick count modulo a specified value. |
duration::operator*= Operator | Multiplies the stored tick count by a specified value. |
duration::operator/= Operator | Divides the stored tick count by the tick count of a specified duration object. |
duration::operator+ Operator | Returns *this. |
duration::operator++ Operator | Increments the stored tick count. |
duration::operator+= Operator | Adds the tick count of a specified duration object to the stored tick count. |
duration::operator-= Operator | Subtracts the tick count of a specified duration object from the stored tick count. |
더보기
time_point Class
A time_point describes a type that represents a point in time. It holds an object of type duration that stores the elapsed time since the epoch that is represented by the template argument Clock.
A time_point describes a type that represents a point in time. It holds an object of type duration that stores the elapsed time since the epoch that is represented by the template argument Clock.
복사
template< class Clock, class Duration = typename Clock::duration > class time_point;
Public Typedefs
Name | Description |
---|---|
time_point::clock | Synonym for the template parameter Clock. |
time_point::duration | Synonym for the template parameter Duration. |
time_point::period | Synonym for the nested type name duration::period. |
time_point::rep | Synonym for the nested type name duration::rep. |
Public Constructors
Name | Description |
---|---|
time_point::time_point Constructor | Constructs a time_point object. |
Public Methods
Name | Description |
---|---|
time_point::max Method | Specifies the upper limit for time_point::ref. |
time_point::min Method | Specifies the lower limit for time_point::ref. |
time_point::time_since_epoch Method | Returns the stored duration value. |
Public Operators
Name | Description |
---|---|
time_point::operator+= Operator | Adds a specified value to the stored duration. |
time_point::operator-= Operator | Subtracts a specified value from the stored duration. |
더보기
system_clock Struct
Represents a clock type that is based on the real-time clock of the system.
Represents a clock type that is based on the real-time clock of the system.
복사
struct system_clock;
A clock type is used to obtain the current time as UTC. The type embodies an instantiation of duration and the class template time_point, and defines a static member function now() that returns the time.
A clock is monotonic if the value that is returned by a first call to now() is always less than or equal to the value that is returned by a subsequent call to now().
A clock is steady if it is monotonic and if the time between clock ticks is constant.
In this implementation, a system_clock is synonymous with a high_resolution_clock.
A clock is monotonic if the value that is returned by a first call to now() is always less than or equal to the value that is returned by a subsequent call to now().
A clock is steady if it is monotonic and if the time between clock ticks is constant.
In this implementation, a system_clock is synonymous with a high_resolution_clock.
Public Typedefs
Name | Description |
---|---|
system_clock::duration | A synonym for duration<rep, period>. |
system_clock::period | A synonym for the type that is used to represent the tick period in the contained instantiation of duration. |
system_clock::rep | A synonym for the type that is used to represent the number of clock ticks in the contained instantiation of duration. |
system_clock::time_point | A synonym for time_point<Clock, duration>, where Clock is a synonym for either the clock type itself or another clock type that is based on the same epoch and has the same nested duration type. |
Public Methods
Name | Description |
---|---|
system_clock::from_time_t Method | Static. Returns a time_point that most closely approximates a specified time. |
system_clock::now Method | Static. Returns the current time. |
system_clock::to_time_t Method | Static. Returns a time_t object that most closely approximates a specified time_point. |
Public Constants
Name | Description |
---|---|
system_clock::is_monotonic Constant | Specifies whether the clock type is monotonic. |
system_clock::is_steady Constant | Specifies whether the clock type is steady. |
더보기
steady_clock Struct
Represents a steady clock.
Represents a steady clock.
복사
struct steady_clock;
On Windows, steady_clock wraps the QueryPerformanceCounter function.
A clock is monotonic if the value that is returned by a first call to now() is always less than or equal to the value that is returned by a subsequent call to now().
A clock is steady if it is monotonic and if the time between clock ticks is constant.
High_resolution_clock is a typdef for steady_clock.
A clock is monotonic if the value that is returned by a first call to now() is always less than or equal to the value that is returned by a subsequent call to now().
A clock is steady if it is monotonic and if the time between clock ticks is constant.
High_resolution_clock is a typdef for steady_clock.
cpp reference 사이트의
chrono : http://en.cppreference.com/w/cpp/header/chrono
time_point : http://en.cppreference.com/w/cpp/chrono/time_point
duration : http://en.cppreference.com/w/cpp/chrono/duration
코드예-1 |
||||
현재시각 구하기. (epoch이후의 경과시간)
설명. 1. now() 함수 호출한 시점의 "시각"이 자료형 time_point 변수 tp_Now 에 저장된다. 2. 상기1에서 "시각"이라함은 epoch(UTC 1970년 1월 1일 0시0분0초 시점) 이후 now 호출한 시점까지의 나노초 단위의 경과시간. 3. 상기2의 epoch이후의 경과시간은 time_point 의 멤버 함수 time_since_epoch() 호출하여 duration 형 변수 duEpoch로 받았다. 4. duEpoch.count() 함수 호출로 64비트 정수형 변수 TimeIntervalEpoch_64 으로 받았다. 주의사항: nanoseconds 로 명시적 형변환 해야만 정확한 값을 받을 수 있음. nanoseconds 로 형변환 하지 않은 경우엔 반환값이 나노도 아니고, 마이크로 초도 아닌 나노초 기준 100으로 나눈값이 반환됨. nanoseconds 로 명시적 형변환 한 경우 : epoch 이후 경과한 정확한 나노초 : 1456136176997090600 명시적 형변환 없이 duEpoch.count(); 로 그냥 받은 경우 : 14561361769970906 상기 대비 100으로 나눈값임. 코드의 특정 처리구간 시간격 구하기.
|
||||
코드예-2. 당일 0시 이후 현재까지 경과시간 나노초 단위로 받기. |
||||
아래 코드에 사용된 std::time_t, std:tm 상세 보기 : http://igotit.tistory.com/673
실행결과.
|
||||
코드예-3. 실수형으로 받기. |
||||
상기 코드예-2의 마지막에 아래 코드 추가.
실행결과.
|
||||
연관
std::time_t, std::tm
개요 std::time_t epoch (1970년 1월 1일 0시0분0초)이후 현재까지의 초단위 경과시간. std::tm 년,월,일,시,분,초 분리 처리시 용이. 헤더파일 #include 코드예-1. 현재시간 받고 년월일시분초 분리. std::time_t..
igotit.tistory.com
상위정리
Visual Studio/VC++/C/C# 활용정리 -> http://igotit.tistory.com/11
Visual Studio , Visual C++ 활용 정리.
Visual Studio C++ 활용 Visual Studio Visual C++ / C# 1.설치, 설정 주제 비고. Visual Studio 2010 설치. Visual Studio 2013 (Community)무료 설치. Visaul Studio 2015 (Community)무료 설치...
igotit.tistory.com
첫 등록 : 2016.02.20
최종 수정 : 2022.03.07
단축 주소 : https://igotit.tistory.com/672
'VisualStudio.C++.C# > C . C++' 카테고리의 다른 글
C++ 클래스. 함수 오버라이딩. 가상함수. 순수가상함수. 추상 클래스.인터페이스 클래스. (0) | 2017.06.23 |
---|---|
C++ 클래스 static 변수 초기화. (0) | 2017.03.13 |
C/C++ 실수형 float, double 표준 IEEE754. 실수자료형 사용시 주의사항. (0) | 2016.02.18 |
C++ std::thread 클래스 이용한 스레드. 클래스멤버함수를 스레드로 실행시키는 방법. (0) | 2016.01.16 |
C++. 함수 인자로 포인터 전달하고 함수내에서 동적 메모리 할당 받기 2가지 방식. ** *& (1) | 2016.01.04 |
댓글