Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <time.h>
- #include <math.h>
- #define LOOP_LIMIT 10000
- #define MAX( a, b ) ((a) > (b) ? (a) : (b))
- int main(void) {
- int i, j;
- double x, y;
- clock_t stime, etime;
- stime = clock();
- for (i = 0; i < LOOP_LIMIT; i++) {
- for (j = 0; j < LOOP_LIMIT; j++) {
- x = i * 1.0;
- y = j * 2.0;
- x = MAX(x, y);
- }
- }
- etime = clock();
- printf("MACRO Version : time = %g\n",
- (double) (etime - stime) / CLOCKS_PER_SEC);
- stime = clock();
- for (i = 0; i < LOOP_LIMIT; i++) {
- for (j = 0; j < LOOP_LIMIT; j++) {
- x = i * 1.0;
- y = j * 2.0;
- x = fmax(x, y);
- }
- }
- etime = clock();
- printf("FUNCTION Version : time = %g\n",
- (double) (etime - stime) / CLOCKS_PER_SEC);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement