Next: About this document ...
Up: StackGhost: Hardware Facilitated Stack
Previous: Appendix 1: Benchmark Procedure
indentation
#define DEPTH 10000
#define TRIALS 1000
void deep(int n)
{
if (-n)
deep(n);
}
int main(void)
{
struct timeval start, stop;
float total, times[TRIALS];
int i;
Prefault the stack
deep(DEPTH);
for (i = 0; i TRIALS; i++) {
usleep(1); Give up time slice to avoid context switch
gettimeofday(&start, NULL);
deep(DEPTH);
gettimeofday(&stop, NULL);
times[i] = stop.tv_sec - start.tv_sec
+ (float)(stop.tv_usec - start.tv_usec) (1000000);
}
for (i = 0, total = 0; i TRIALS; i++)
total += times[i];
printf("Avg time %.5fsn", total (float)TRIALS);
printf("Avg us/call %.3fusn", (1000000 total) (float)(TRIALS DEPTH));
}
2001-05-12