본문 바로가기
개발개발/c++

🍯 꿀팁 : 성능 테스트를 위한 시간 계산코드

by 유잉유잉유잉 2025. 1. 9.
728x90
#include <iostream>
#include <Windows.h>

int main()
{
	int testCount = 100000;
	LARGE_INTEGER	Second;
	LARGE_INTEGER	Time;

	QueryPerformanceFrequency(&Second);
	QueryPerformanceCounter(&Time);
    
    // 측정할 횟수(testCount) 설정하여 반복
    for (int i = 0 ; i < testCount ; ++i)
    {
    	// 반복시 측정할 함수나 연산 등 넣기 
        Print(item);
    }
    
    LARGE_INTEGER	Time1;
    QueryPerformanceCounter(&Time1);

    double	Rate = (Time1.QuadPart - Time.QuadPart) /
        (double)Second.QuadPart;

    std::cout << "time : " << Rate << std::endl;
    
	return 0;
}
728x90

댓글