/****************************************************************************** Welcome to GDB Online. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl, C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog. Code, Compile, Run and Debug online from anywhere in world. *******************************************************************************/ #include <stdio.h> #include <math.h> #include <time.h> int nmbr=1; int t_int =0; int milliseconds = 500; double cpu_time_used, process_time; int main() { //time initialization clock_t t_1, t_2, t_start, t_end; t_start = clock(); t_1 = 0; t_2 = t_1; while (t_int<8) { t_1 = clock(); ////sleep int ms_remaining = milliseconds % 1000; long usec = ms_remaining * 1000; struct timespec ts_sleep; ts_sleep.tv_sec = (milliseconds) / 1000; ts_sleep.tv_nsec = 1000*usec; nanosleep(&ts_sleep, NULL); cpu_time_used = ((double) (t_1 - t_2)); /// CLOCKS_PER_SEC; printf("Hello World %i, time : %f \n",nmbr, cpu_time_used); t_2 = t_1; nmbr++; t_int++; } t_end = clock(); process_time = ((double) (t_end - t_start)) / CLOCKS_PER_SEC; printf("INTERRUPTED, process time :%f \n", process_time); }
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more