Warning: Declaration of action_plugin_changes::register($controller) should be compatible with DokuWiki_Action_Plugin::register(Doku_Event_Handler $controller) in /volume1/web/dokuwiki/lib/plugins/changes/action.php on line 0 Warning: Declaration of syntax_plugin_code::handle($aMatch, $aState, $aPos, &$aHandler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in /volume1/web/dokuwiki/lib/plugins/code/syntax.php on line 42 Warning: Declaration of syntax_plugin_code::render($aFormat, &$aRenderer, &$aData) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in /volume1/web/dokuwiki/lib/plugins/code/syntax.php on line 42 c_exec_time [Protocol Engineering Lab.]

User Tools

Site Tools


c_exec_time
/* exec_time.c: check the execution time of function(s) */
/* able to measure in milli-seconds (ms) */
 
#include <stdio.h>
#include <sys/time.h>
 
void func(void);
 
int main(void) {
 
    struct timeval tv1, tv2;
 
    gettimeofday(&tv1, NULL);
    func();
    gettimeofday(&tv2, NULL);
 
    printf ("Total time = %f seconds\n",
            (double) (tv2.tv_usec - tv1.tv_usec) / 1000000 +
            (double) (tv2.tv_sec - tv1.tv_sec));
 
    return(0);
}
 
void func(void) {
    int i;
    int p[10];
 
    for(i = 0; i < 3; i++) {
        printf("%d\n", p[i] = i);
        sleep(1);
    }
}
c_exec_time.txt · Last modified: 2015/02/07 05:08 by jonghyouk