fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5.  
  6. #define DATA_NUM 10000
  7. #define LOOP_NUM 10
  8.  
  9.  
  10. void bubble_sort(int data[], int data_num)
  11. {
  12. int i, j, t;
  13.  
  14. for(i=0;i<data_num;i++)
  15. {
  16. for(j=0;j+1<data_num-i;j++)
  17. {
  18. if(data[j]>data[j+1])
  19. {
  20. t=data[j];
  21. data[j]=data[j+1];
  22. data[j+1]=t;
  23. }
  24. }
  25. }
  26. }
  27.  
  28.  
  29. int main(void)
  30. {
  31. static int data[DATA_NUM], org[DATA_NUM];
  32. clock_t s, e;
  33. int i;
  34.  
  35. for(i=0;i<DATA_NUM;i++)
  36. {
  37. org[i]=rand();
  38. }
  39. s=clock();
  40. for(i=0;i<LOOP_NUM;i++)
  41. {
  42. memcpy(data, org, sizeof(org));
  43. bubble_sort(data, DATA_NUM);
  44. }
  45. e=clock();
  46. printf("%.3f [sec] %d\n", (double)(e-s)/CLOCKS_PER_SEC, data[0]);
  47.  
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 1.74s 2324KB
stdin
Standard input is empty
stdout
1.740 [sec] 100669