일상 코딩
[C++/10.05] 의존 관계, Dependecy on, Timer, Chrono 본문
C++/따배C++ 10강 객체들 사이의 관계
[C++/10.05] 의존 관계, Dependecy on, Timer, Chrono
polarcompass 2021. 11. 3. 23:01728x90
1. main.cpp
#include "Worker.h"
// using namespace std;
int main()
{
Worker().doSomething();
return 0;
}
2. Timer.h
#pragma once
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <algorithm>
class Timer
{
private:
using clock_t = std::chrono::high_resolution_clock;
using second_t = std::chrono::duration<double, std::ratio<1>>;
std::chrono::time_point<clock_t> start_time = clock_t::now();
public:
void elapsed()
{
std::chrono::time_point<clock_t> end_time = clock_t::now();
std::cout << std::chrono::duration_cast<second_t>(end_time - start_time).count() << std::endl;
}
};
3. Worker.h
#pragma once
class Worker
{
public:
void doSomething();
};
4. Worker.cpp
// #pragma once
#include "Timer.h"
#include "Worker.h"
void Worker::doSomething()
{
Timer timer; // start timer
int hap = 0;
for (int i = 0; i < 10000; i++)
{
hap += i;
}
timer.elapsed();
}
728x90
'C++ > 따배C++ 10강 객체들 사이의 관계' 카테고리의 다른 글
[C++/10.04] 제휴 관계, Association (0) | 2021.11.03 |
---|---|
[C++/10.03] Aggregation 집합 관계 (0) | 2021.11.02 |
[C++/10.02] Composition 구성 관계 (0) | 2021.10.31 |