Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Clojure
- go
- template
- type_traits
- Android
- WebView
- traits
- sprintf
- Observer
- c++
- coroutines
- design pattern
- Chrono
- async
- RAII
- Scala
- kotlin
- ranges
- Reflect
- program
- Functional
- web
- stringprintf
- haskell
- SHA512
- sha256
- AES
- SHA1
- ChromeTab
- CustomTab
Archives
- Today
- Total
프로그래밍 검색 블로그
시간 관련 API 본문
std chrono
관련 유틸 제작
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include <chrono> namespace System{ long long currentTimeNanoseconds() { auto time = std::chrono::system_clock::now(); return std::chrono::duration_cast<std::chrono::nanoseconds>(time.time_since_epoch()).count(); } long long currentTimeMillis() { auto time = std::chrono::system_clock::now(); return std::chrono::duration_cast<std::chrono::milliseconds>(time.time_since_epoch()).count(); } long long currentTimeSeconds() { auto time = std::chrono::system_clock::now(); return std::chrono::duration_cast<std::chrono::seconds>(time.time_since_epoch()).count(); } int currentTimeMinutes() { auto time = std::chrono::system_clock::now(); return (int)(std::chrono::duration_cast<std::chrono::minutes>(time.time_since_epoch()).count()); } } | cs |
자바의 그것
+추가
콘솔 프로그래밍으로 모듈 만들었을때 시간 검사용
1 2 3 4 5 6 7 8 9 10 11 | #include <iostream> struct __TIME__CHECK__ { const long long begin; __TIME__CHECK__() : begin(System::currentTimeMillis()){} ~__TIME__CHECK__() { const long long end = System::currentTimeMillis(); std::cout <<"Elapsed Time: "<< (end - begin) << std::endl; } explicit operator const bool() { return true; } }; #define timecheck if (__TIME__CHECK__ _TIME_CHECK_RUN_{}) |
}
로 블럭을 만들고 이 안에 시간 검사가 필요한 기능을 넣으면 얼마나 걸렸는지 체크가 가능
테스트
1 2 3 4 5 6 7 8 9 10 | #include <iostream> using namespace std; int main(int argc, const char * argv[]) { timecheck{ for(int i = 0; i < 1000; i++){ cout << System::currentTimeNanoseconds()<<endl; } } } | cs |
'C++ 유틸' 카테고리의 다른 글
C++ 컬렉션 필터링 (0) | 2017.10.07 |
---|---|
함수가 끝날때 같이 해제하기 defer (0) | 2017.10.06 |
stringprintf string반환 sprintf 2 (0) | 2017.10.04 |
stringprintf string반환 sprintf 1 (0) | 2017.10.04 |
C++ Traits (0) | 2017.10.03 |
Comments