Azinix

perf.c File Reference

#include "util.h"
#include "timing.h"
#include <stdio.h>
#include <math.h>
#include <time.h>

Go to the source code of this file.

Defines

#define MAXN   100000
 Code from Jon Bentley's Programming Pearls book for measuring times used by various C constructs. http://www.cs.bell-labs.com/cm/cs/pearls/code.html.
#define swapmac(i, j)   { t = x[i]; x[i] = x[j]; x[j] = t; }
#define maxmac(a, b)   ((a) > (b) ? (a) : (b))
#define T(s)   printf("%s (n=%d)\n", s, n);
#define TRIALS   5
#define M(op)
#define MEASURE(T, text)
 Code for testing space usage of various C constructs. From Bentley (see above).
#define BASEN   100000000
 Another version of a timing program from www/cs/vu.nl/pub/leendert/cputimes.c.
#define WARNRANGE   0.4
#define CLOCKS_PER_SEC   60
#define quoted(TEXT)   "TEXT"
#define loop1(CODE)
#define loop(CODE)
#define title(TEXT)   printf("%s (n=%d)\n", TEXT, n);

Typedefs

typedef stacknode * Stackp

Functions

int Perf_CheckTimingCode (ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
 Testing the resolution of the rdtsc timing code.
int Perf_CheckHardware (ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
 Routine to determine machine dependent parameters.
int Perf_TimePerf (ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
int Perf_SpacePerf (ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
void push (int i)
int pop ()
int sum1 (int a)
int sum2 (int a, int b)
int sum3 (int a, int b, int c)
int Perf_TimePerf2 (ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])

Variables

Stackp stackroot


Define Documentation

#define BASEN   100000000

Another version of a timing program from www/cs/vu.nl/pub/leendert/cputimes.c.

Definition at line 454 of file perf.c.

#define CLOCKS_PER_SEC   60

Definition at line 458 of file perf.c.

#define loop ( CODE   ) 

Value:

printf("  %-30s", quoted(CODE)); \
        minclicks = 99999999; maxclicks = -1; sumclicks = 0; \
        loop1ctr = 0; \
        loop1start = clock(); \
        loop1(CODE) \
        loop1(CODE) \
        i0 = i1 + i2 + i3; \
        loop1(CODE) \
        i0 = i1 + i2 + i3 - i1 - i2 - i3; \
        loop1(CODE) \
        i0 = i1 + i2 + i3 + i1*i2 + i2*i3 + i1*i3; \
        loop1(CODE) \
        queststr = ""; \
        if (loop1ctr * (float)(maxclicks - minclicks) > WARNRANGE *  sumclicks) \
                queststr = "?"; \
        lastmics = sumclicks * 1000000.0 / ((float)(CLOCKS_PER_SEC) * n * loop1ctr); \
        printf("%10.6f%s\n", lastmics - basemics, queststr);

Definition at line 509 of file perf.c.

#define loop1 ( CODE   ) 

Value:

loop1ctr++; \
        for (i = 0; i < n; i++) { CODE; } \
        loop1next = clock(); \
        thisclicks = loop1next - loop1start; \
        sumclicks += thisclicks; \
        if (thisclicks < minclicks) minclicks = thisclicks; \
        if (thisclicks > maxclicks) maxclicks = thisclicks; \
        printf("%5d", (loop1next - loop1start)/1000); \
        loop1start = loop1next;

Definition at line 499 of file perf.c.

#define M ( op   ) 

Value:

printf(" %-22s", #op);              \
    k = 0;                              \
    timesum = 0;                        \
    for (ex = 0; ex < TRIALS; ex++) {   \
        start = clock();                \
        for (i = 1; i <= n; i++) {      \
            fi = (float) i;             \
            for (j = 1; j <= n; j++) {  \
                op;                     \
            }                           \
        }                               \
        t = clock()-start;              \
        printf("%6d", t);               \
        timesum += t;                   \
    }                                   \
    nans = 1e9 * timesum / ((double)    \
        n*n * TRIALS * CLOCKS_PER_SEC); \
    printf("%8.0f\n", nans);

Definition at line 163 of file perf.c.

#define maxmac ( a,
 )     ((a) > (b) ? (a) : (b))

Definition at line 150 of file perf.c.

#define MAXN   100000

Code from Jon Bentley's Programming Pearls book for measuring times used by various C constructs. http://www.cs.bell-labs.com/cm/cs/pearls/code.html.

Definition at line 127 of file perf.c.

#define MEASURE ( T,
text   ) 

Value:

{                   \
    printf("%s\t", text );      \
    printf("sizeof(%s) = %d\t", #T, sizeof(T) );                \
    int lastp = 0;                          \
    int i;  \
    for (i = 0; i < 11; i++) {          \
        T *p = (T *) malloc( sizeof( T ) );                     \
        int thisp = (int) p;                \
        if (lastp != 0)                     \
            printf(" %d ", thisp - lastp ); \
        lastp = thisp;                      \
    }                                       \
    printf("\n"); \
}
Code for testing space usage of various C constructs. From Bentley (see above).

Definition at line 276 of file perf.c.

#define quoted ( TEXT   )     "TEXT"

Definition at line 464 of file perf.c.

#define swapmac ( i,
 )     { t = x[i]; x[i] = x[j]; x[j] = t; }

Definition at line 140 of file perf.c.

#define T (  )     printf("%s (n=%d)\n", s, n);

Definition at line 161 of file perf.c.

#define title ( TEXT   )     printf("%s (n=%d)\n", TEXT, n);

Definition at line 527 of file perf.c.

#define TRIALS   5

Definition at line 162 of file perf.c.

#define WARNRANGE   0.4

Definition at line 455 of file perf.c.


Typedef Documentation

typedef struct stacknode* Stackp

Definition at line 472 of file perf.c.


Function Documentation

int Perf_CheckHardware ( ClientData  cd,
Tcl_Interp *  interp,
int  objc,
Tcl_Obj *const  objv[] 
)

Routine to determine machine dependent parameters.

Definition at line 37 of file perf.c.

int Perf_CheckTimingCode ( ClientData  cd,
Tcl_Interp *  interp,
int  objc,
Tcl_Obj *const  objv[] 
)

Testing the resolution of the rdtsc timing code.

Definition at line 10 of file perf.c.

int Perf_SpacePerf ( ClientData  cd,
Tcl_Interp *  interp,
int  objc,
Tcl_Obj *const  objv[] 
)

Definition at line 378 of file perf.c.

int Perf_TimePerf ( ClientData  cd,
Tcl_Interp *  interp,
int  objc,
Tcl_Obj *const  objv[] 
)

Definition at line 185 of file perf.c.

int Perf_TimePerf2 ( ClientData  cd,
Tcl_Interp *  interp,
int  objc,
Tcl_Obj *const  objv[] 
)

Definition at line 550 of file perf.c.

int pop (  ) 

Definition at line 487 of file perf.c.

void push ( int  i  ) 

Definition at line 476 of file perf.c.

int sum1 ( int  a  ) 

Definition at line 532 of file perf.c.

int sum2 ( int  a,
int  b 
)

Definition at line 538 of file perf.c.

int sum3 ( int  a,
int  b,
int  c 
)

Definition at line 544 of file perf.c.


Variable Documentation

Stackp stackroot

Definition at line 473 of file perf.c.