#include // clock(), clock_t, CLK_TCK #include // printf() #include // gotoxy() #define REPS_1 (100000000L) #define REPS_2 (10000000L) #define REPS_3 (100000L) int main(void) { long i; clock_t start, stop; double passtime; // Time an empty loop for reference purposes start = clock(); for(i = 0; i < REPS_1; i++) ; stop = clock(); gotoxy(1, 2); printf("Start, Stop : "); printf("<%li, %li>\n", (long) start, (long) stop); passtime = ((double)(stop - start)/(double) CLK_TCK) / (double) REPS_1; printf("Time to execute each pass of empty loop: "); printf("%.3f us\n", 1e6*passtime); // Time loop that moves the screen cursor start = clock(); for(i = 0; i < REPS_2; i++) gotoxy(10,24); stop = clock(); gotoxy(1, 5); printf("Start, Stop : "); printf("<%li, %li>\n", (long) start, (long) stop); passtime = ((double)(stop - start)/(double) CLK_TCK) / (double) REPS_2; printf("Time to execute each pass of loop with screen cursor move: "); printf("%.3f us\n", 1e6*passtime); // Time loop that outputs a character to the screen start = clock(); for(i = 0; i < REPS_3; i++) { gotoxy(10,24); printf("*"); } stop = clock(); gotoxy(1, 8); printf("Start, Stop : "); printf("<%li, %li>\n", (long) start, (long) stop); passtime = ((double)(stop - start)/(double) CLK_TCK) / (double) REPS_3; printf("Time to execute each pass of loop with screen output: "); printf("%.3f us\n", 1e6*passtime); // Time loop that outputs ten characters to the screen start = clock(); for(i = 0; i < REPS_3; i++) { gotoxy(10,24); printf("0123456789"); } stop = clock(); gotoxy(1, 11); printf("Start, Stop : "); printf("<%li, %li>\n", (long) start, (long) stop); passtime = ((double)(stop - start)/(double) CLK_TCK) / (double) REPS_3; printf("Time to prints ten characters: "); printf("%.3f us\n", 1e6*passtime); // Time loop that outputs ten characters to the screen with two calls start = clock(); for(i = 0; i < REPS_3; i++) { gotoxy(10,24); printf("01234"); printf("56789"); } stop = clock(); gotoxy(1, 14); printf("Start, Stop : "); printf("<%li, %li>\n", (long) start, (long) stop); passtime = ((double)(stop - start)/(double) CLK_TCK) / (double) REPS_3; printf("Time to printf 2x5 characters: "); printf("%.3f us\n", 1e6*passtime); return(0); }