-
-
Save kongr45gpen/269d32cafc307b6bce44d9ffd0856ed0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <time.h> | |
#define REP 200000000 | |
double kybos1(float); | |
double ginomeno1(float,float,float); | |
double kybos2(float); | |
double ginomeno2(float,float,float); | |
int main() { | |
clock_t begin1, end1,begin2, end2; | |
double time_spent1, time_spent2; | |
float x,y,z; | |
double fu = 0; | |
int i; | |
begin1 = clock(); | |
for (i = 0; i < REP; i++){ | |
x = y = z = i; | |
// Γίνεται πρόσθεση στην fu ώστε να μην αγνοήσει την πράξη ο compiler | |
// (αφού διαφορετικά δεν θα υπάρχει αποτέλεσμα που πρέπει να | |
// εμφανιστεί, άρα δεν υπάρχει λόγος να γίνει η πράξη) | |
fu += kybos1(x) + ginomeno1(x,y,z); | |
} | |
end1 = clock(); | |
printf("fu 1 = %lf\n",fu); | |
time_spent1 = (double) (end1 - begin1) / CLOCKS_PER_SEC; | |
fu = 0; | |
begin2 = clock(); | |
for (i = 0; i < REP; i++){ | |
x = y = z = i; | |
fu += kybos2(x) + ginomeno2(x,y,z); | |
} | |
end2 = clock(); | |
printf("fu 2 = %lf\n",fu); | |
time_spent2 = (double) (end2 - begin2) / CLOCKS_PER_SEC; | |
printf("Time 1 = %lf\nTime 2 = %lf\n", time_spent1, time_spent2); | |
return 0; | |
} | |
double kybos1(float x) { | |
return x*x*x; | |
} | |
double ginomeno1(float x, float y, float z) { | |
return x*y*z; | |
} | |
double kybos2(float x) { | |
double t; | |
t=x*x*x; | |
return t; | |
} | |
double ginomeno2(float x, float y, float z) { | |
double t; | |
t=x*y*z; | |
return t; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment