Skip to content

Instantly share code, notes, and snippets.

@jbdrvl
Last active April 16, 2018 21:23
Show Gist options
  • Select an option

  • Save jbdrvl/0196f5c5962fc7117cc387d259862ac9 to your computer and use it in GitHub Desktop.

Select an option

Save jbdrvl/0196f5c5962fc7117cc387d259862ac9 to your computer and use it in GitHub Desktop.
simple <clocks> presentation in C
#include <time.h>
#include <stdio.h>
int main () {
clock_t start_t, end_t, total_t;
long i;
start_t = clock();
printf("Starting of the program, start_t = %ld clockUnits\n", start_t);
printf("Going to scan a big loop, start_t = %ld clockUnits\n", start_t);
for(i=0; i< 9929999999; i++) {
}
end_t = clock();
printf("End of the big loop, end_t = %ld clockUnits\n", end_t);
total_t = (double)(end_t - start_t) / CLOCKS_PER_SEC;
printf("Total time taken by CPU: %ld seconds\n", total_t );
printf("Counting to 4\n");
while (total_t<(double)4) {
end_t = clock();
total_t = (double)(end_t - start_t) / CLOCKS_PER_SEC;
}
printf("Exiting of the program...\n");
return(0);
}
all : main
main : main.o
gcc main.o -Wall -o main
main.o : main.c
gcc -W -Wall -c main.c -o main.o
run : main
rm main.o
./main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment