/* Compile: gcc cpubound.c -lm -o cpubound Usage: ./cpubound [N] */ #include #include #include #include #include int main(int argc, char *argv[]) { int n = 1, n_max, i; double a = 123.0, b; clock_t t0, t1; if ( argc > 2 || ( argc == 2 && strcmp(argv[1],"-h") == 0 ) ) { printf("Usage: ./cpubound [n]\n"); printf("CPU consumed is approximately t(n)=n*t(0), n = 1,2,...\n"); return 0; } if ( argc == 2 ) { n = atoi(argv[1]); } n_max = n * 5000000; t0 = clock(); for (i = 0; i < n_max; i++) b = exp(a)/exp(a); t1 = clock(); printf("Elapsed Time: %f\n", (t1-t0)/(double)CLOCKS_PER_SEC); return 0; }