#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 BASEN 100000000 |
| #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);
| #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;
| #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);
| #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 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"); \
}
| #define swapmac | ( | i, | |||
| j | ) | { t = x[i]; x[i] = x[j]; x[j] = t; } |
| int Perf_CheckHardware | ( | ClientData | cd, | |
| Tcl_Interp * | interp, | |||
| int | objc, | |||
| Tcl_Obj *const | objv[] | |||
| ) |
| int Perf_CheckTimingCode | ( | 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[] | |||
| ) |
| int Perf_TimePerf | ( | ClientData | cd, | |
| Tcl_Interp * | interp, | |||
| int | objc, | |||
| Tcl_Obj *const | objv[] | |||
| ) |
| int Perf_TimePerf2 | ( | ClientData | cd, | |
| Tcl_Interp * | interp, | |||
| int | objc, | |||
| Tcl_Obj *const | objv[] | |||
| ) |