본문 바로가기
Computer/Algorithm

[Algorithm] 수행시간 측정 방법

by 생각하는달팽이 2015. 3. 3.

향후 알고리즘의 시간 측정은 다음과 같은 방법으로 진행된다.


#include <stdio.h>

#include <time.h>


int main(int argc, const char * argv[]) {

    // insert code here...

    clock_t start_time, end_time; // Time Variable Declare

    

    start_time = clock(); // Time to start

    

    // Here is Some Code

    

    end_time = clock(); // Time to end

    

    printf("Time : %f\n", ((double)(end_time-start_time)) / CLOCKS_PER_SEC);


    return 0;

}



Here is Some Code 라고 주석으로 명시한 부분에 내가 수행할 코드를 넣기로 한다. 


추가로 여러 운영체제에 대응해서 만든 헤더파일 삽입 요령입니다.



#ifdef _WIN64 // define something for Windows (64-bit)
#include <sys/time.h>

#elif _WIN32 // define something for Windows (32-bit)

#include <sys/time.h>

#elif __APPLE__ // apple

#include <sys/time.h>

#elif __linux // linux

#include <time.h>

#elif __unix // Unix

#include <time.h>

#elif __posix // POSIX

#include <time.h>

#endif


반응형

'Computer > Algorithm' 카테고리의 다른 글

[Algorithm] Selection sort, Insertion sort  (0) 2015.03.04
알고리즘 기초  (0) 2015.02.11