]> git.piffa.net Git - arduino/blob - books/ArduinoNextSteps-master/benchmark.c
first commit
[arduino] / books / ArduinoNextSteps-master / benchmark.c
1 // benchmark.c
2 #include <stdio.h>
3 #include <time.h>  
4
5 main()
6 {
7   printf("\nStarting Test\n");
8   time_t startTime = clock();
9   
10   // test code here
11   long  i = 0;
12   long j = 0;
13   for (i = 0; i < 20000000; i ++)
14   {
15     j = i + i * 10;
16     if (j > 10) j = 0;
17   }
18   // end of test code
19   time_t endTime = clock();
20   
21   printf("%ld\n", j); // prevent loop being optimized out
22   printf("Finished Test\n");
23   double timeSpent = (double)(endTime - startTime) / CLOCKS_PER_SEC;
24   printf("seconds taken: %f\n", timeSpent); 
25   return 0;
26 }