/* * Operating Systems Class * Fall 2006, Professor Yap. * THIS code is adapted from the website * http://beige.ucs.indiana.edu/B673/node104.html by Zdzislaw Meglicki */ #include #include #include #include #include main() { time_t t0, t1; clock_t c0, c1; long count; double a, b, c; t0 = time(NULL); c0 = clock(); printf ("\tbegin time in sec: %ld\n", (long) t0); printf ("\tbegin clock ticks: %d\n", (int) c0); printf ("\t\tsleep for 2 seconds ... \n"); sleep(2); printf ("\t\tperform some computation ... \n"); for (count = 1l; count < 10000000l; count++) { a = sqrt(count); b = 1.0/a; c = b - a; } t1 = time(NULL); c1 = clock(); printf ("\tend time in sec: %ld\n", (long) t1); printf ("\tend clock ticks: %d\n", (int) c1); printf ("\telapsed elapsed time in sec: %ld\n", (long) (t1 - t0)); printf ("\telapsed elapsed ticks in sec: %f\n", (float) (c1 - c0)/CLOCKS_PER_SEC); }