Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
this
#include <stdio.h> #include <time.h> #include <math.h> //#define maxitr 500000000 /*ELE709 Lab 2.*/ int main() { int i, maxitr = 500000000; double a, b, c; char op; struct timespec start_time, stop_time, res; double tmp; do{ printf("Welcome to the Experiment.\n"); printf("Please enter the first value: \n"); scanf("%lf",&a); printf("Please enter the operation: \n"); scanf("%c",&op); printf("Please enter the second value: \n"); scanf("%lf",&b); clock_getres(CLOCK_REALTIME, &res); clock_gettime(CLOCK_REALTIME, &start_time); if(op == '+'){ for(i = 0; i < maxitr; i++) { c = a + b; } printf("The sum is: %lf\n", c); } else if (op == '-'){ for(i = 0; i < maxitr; i++) { c = a - b; } printf("The difference is: %lf\n", c); } else if (op == '/') { for(i = 0; i < maxitr; i++) { c = a / b; } printf("The resultant is: %lf\n", c); } else if (op == '*') { for(i = 0; i < maxitr; i++) { c = a * b; } printf("The product is: %lf\n", c); } else { printf("Invalid input.\n"); } clock_gettime(CLOCK_REALTIME, &stop_time); tmp = (stop_time.tv_nsec-start_time.tv_nsec);///maxitr; printf("The operation took an average time of %lf ns long to complete.", (tmp/maxitr)); /* sleep_time.tv_sec = 0; sleep_time.tv_nsec = 20000000; printf("Sleep time requested is %ld sec %ld nsec\n", sleep_time.tv_sec, sleep_time.tv_nsec); itr = 10; for(i = 0; i < itr; i++) { clock_gettime(CLOCK_REALTIME, &start_time); nanosleep(&sleep_time,NULL); clock_gettime(CLOCK_REALTIME, &stop_time); tmp = (stop_time.tv_sec - start_time.tv_sec)*1e9; tmp += (stop_time.tv_nsec - start_time.tv_nsec); elapsed_time[i] = tmp; } for(i = 0; i < itr; i++) { printf("Iteration %2d ... Slept for %lf nsec\n", i, elapsed_time[i]); }*/ return 0; }while (NULL); }
run
|
edit
|
history
|
help
0
REGISTRO EN C
Bitwise Operations
A_141205_Palindromo
Stack frame enum test
Conflito de Escrita em Matriz
gkckibvsj
qsort para struct
lab 12 v0.1
htabprepa
Camping