Subversion Repositories Code-Repo

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
141 Kevin 1
/****************************
2
 * High-level timing wrappers
3
 ****************************/
4
#include <stdio.h>
5
#include "fsecs.h"
6
#include "fcyc.h"
7
#include "clock.h"
8
#include "ftimer.h"
9
#include "config.h"
10
 
11
static double Mhz;  /* estimated CPU clock frequency */
12
 
13
extern int verbose; /* -v option in mdriver.c */
14
 
15
/*
16
 * init_fsecs - initialize the timing package
17
 */
18
void init_fsecs(void)
19
{
20
    Mhz = 0; /* keep gcc -Wall happy */
21
 
22
#if USE_FCYC
23
    if (verbose)
24
	printf("Measuring performance with a cycle counter.\n");
25
 
26
    /* set key parameters for the fcyc package */
27
    set_fcyc_maxsamples(20); 
28
    set_fcyc_clear_cache(1);
29
    set_fcyc_compensate(1);
30
    set_fcyc_epsilon(0.01);
31
    set_fcyc_k(3);
32
    Mhz = mhz(verbose > 0);
33
#elif USE_ITIMER
34
    if (verbose)
35
	printf("Measuring performance with the interval timer.\n");
36
#elif USE_GETTOD
37
    if (verbose)
38
	printf("Measuring performance with gettimeofday().\n");
39
#endif
40
}
41
 
42
/*
43
 * fsecs - Return the running time of a function f (in seconds)
44
 */
45
double fsecs(fsecs_test_funct f, void *argp) 
46
{
47
#if USE_FCYC
48
    double cycles = fcyc(f, argp);
49
    return cycles/(Mhz*1e6);
50
#elif USE_ITIMER
51
    return ftimer_itimer(f, argp, 10);
52
#elif USE_GETTOD
53
    return ftimer_gettod(f, argp, 10);
54
#endif 
55
}
56
 
57