/* non-longjmp example */ #include #include /*#include */ #include #define RETURN_NOTHING return; #define ABS_ZERO (1-1) #define BOOLEAN int #define MAX_LOOPS 15000 struct salesinfo { int count; int values[MAX_LOOPS+1]; }; int subtotal; void addvaluetosubtotal(int in_value) { subtotal += in_value; } /* this subroutine is called thousands of times. use longjmp instead of loops to increase speed. Daren 12/03/05 fixed to address speed issue related to use of longjmp Mark 01/02/09 */ void calculate(struct salesinfo*sales){ int i = 0; for(;;) { if (!(icount)) RETURN_NOTHING; addvaluetosubtotal(sales->values[i]); if (icount){ i++; } } } main() { int t, m; struct salesinfo s; time_t timer; timer=time(NULL); printf("Start:%s\n",asctime(localtime(&timer))); for (t=0; t < MAX_LOOPS; t++) { s.values[t] = t; s.count = t+1; } for(m=0; m < 5000; m++) { /* function comment says calculate is called "thousands of times" 5000 should be enough! */ subtotal = 0; calculate(&s); } timer=time(NULL); printf(" End:%s\n\n",asctime(localtime(&timer))); printf("Press Enter to Continue"); getch(); return 0; }