[c, c++] 프로그램 수행 시간 알아내기

kldpzone의 이미지

프로그램 수행 시간을 알아내기 위해

time_t start, end, dif;

time(&start);

&(&(^(^(&

time(&end);

dif = diffimt(start, end);

cout << "time different is " << dif << endl;

이렇게 코드를 짰는데 시간을 초 단위로만 계산하더군요..
혹시 밀리세컨드로 구현하는 방법 알려주시면 감사하겠습니다
서지훈의 이미지

void start_timer(struct timeval *start_time)
{
    gettimeofday(start_time, NULL);
}


void end_timer(struct timeval *end_time)
{
    gettimeofday(end_time, NULL);
}

void processed_time(struct timeval* start, struct timeval *end)
{
    int sec_buf,microsec_buf;
    float time_buf;

    sec_buf = end->tv_sec - start->tv_sec;
    microsec_buf = end->tv_usec - start->tv_usec;

    time_buf = microsec_buf;
    time_buf = time_buf / 1000000;
    time_buf = time_buf + sec_buf;

    printf("[처리 시간]: %f\n", time_buf);
}

이정도면...

<어떠한 역경에도 굴하지 않는 '하양 지훈'>

#include <com.h> <C2H5OH.h> <woman.h>
do { if (com) hacking(); if (money) drinking(); if (women) loving(); } while (1);

doldori의 이미지

#include <ctime>
using namespace std;

int main()
{
    clock_t begin = clock();

    // do something...

    clock_t end = clock();
    double msec = 1000.0 * (end - begin) / CLOCKS_PER_SEC;
}
IsExist의 이미지

단순히 전체 프로그램 시간을 측정한다면 아래명령어가 손 쉽습니다.

$ time command

---------
간디가 말한 우리를 파괴시키는 7가지 요소

첫째, 노동 없는 부(富)/둘째, 양심 없는 쾌락
셋째, 인격 없는 지! 식/넷째, 윤리 없는 비지니스

이익추구를 위해서라면..

다섯째, 인성(人性)없는 과학
여섯째, 희생 없는 종교/일곱째, 신념 없는 정치