Esempio n. 1
0
/* Time measurement function for an empty function call.
   returns time in nano-seconds upon success, 
   and -1 upon failure.
   */
double osm_function_time(unsigned int iterations){
    struct timeval t1;
    struct timeval t2;
    
    if (iterations == 0)
    {
        iterations = DEFAULT_ITERATION;
    }
    
    if (gettimeofday(&t1, NULL) == -1) {
        return -1;
    }
   
    for (unsigned int i = 0; i < iterations; i++) {
        emptyFunc();
        emptyFunc();
        emptyFunc();
        emptyFunc();
        emptyFunc();
    }
    if (gettimeofday(&t2, NULL) == -1) {
        return -1;
    }
    double s = CALCULATE_TIME(t1.tv_sec, t2.tv_sec);
    double us = CALCULATE_TIME(t1.tv_usec, t2.tv_usec);
    return TO_NANO(s, us);
}
Esempio n. 2
0
/**
 * 関数呼び出しのベンチマーク
 * @return 計測時間(ms)
 */
double benchmarkCallFunc(){
    clock_t start_time, end_time;
    volatile int a = 1;
    long i;
    
    start_time = clock();
    for(i = 0; i < BENCHMARK_SIZE; ++i){
        a = emptyFunc();

    }
    end_time = clock();
    return (double)(end_time - start_time)/CLOCKS_PER_SEC;
}