#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
char *s = malloc(1000000 + 1);
printf("<html>\n");
printf("<head>\n");
printf("<link rel=\"stylesheet\" type=\"text/css\" href=\"../teaching.css\">");
printf("</head>\n");
printf("<body>\n");
printf("<table border><td>Length<td>Seconds\n");
for (int nc = 1000; nc <= 1000000; nc *= 10) {
struct timeval tv;
gettimeofday(&tv, NULL); // Get precise start time
int start_msec = ((tv.tv_sec % 86400) * 1000 + tv.tv_usec / 1000);
// This is the part we are timing
int i;
strcpy(s, "");
for (i = 0; i < nc; i++) {
strcat(s, ".");
}
gettimeofday(&tv, NULL); // Get precise end time
long elapsed_msec =((tv.tv_sec % 86400) * 1000 + tv.tv_usec / 1000) - start_msec;
printf("<tr><td>%d<td>%.3f\n", nc, elapsed_msec / 1000.0);
}
printf("</table>\n");
printf("</body>\n");
printf("</html>\n");
exit(0);
}