Check out the new USENIX Web site. next up previous
Next: About this document ... Up: StackGhost: Hardware Facilitated Stack Previous: Appendix 1: Benchmark Procedure

Appendix 2: Micro Benchmark

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;

$/\ast$ Prefault the stack $\ast/$
deep(DEPTH);

for (i = 0; i $<$ TRIALS; i++) {
usleep(1); $/\ast$ Give up time slice to avoid context switch $\ast/$
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 %.5fs$\backslash$n", total $/$ (float)TRIALS);
printf("Avg us/call %.3fus$\backslash$n", (1000000 $\ast$ total) $/$ (float)(TRIALS $\ast$ DEPTH));
}



2001-05-12