Advertisement
Guest User

czesc 1.b

a guest
May 23rd, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. time_t start, stop;
  6.  
  7. float a1;
  8. float b1;
  9.  
  10. void losowanieLiczb() //uzupelnianie wektora liczbami
  11. {
  12. int przedzial1=1000;
  13. float przedzial2 = 4.12;
  14. srand(time(NULL));
  15. a1 = rand()%przedzial1/przedzial2;
  16. b1 = rand()%przedzial1/przedzial2;
  17. }
  18.  
  19. double dodawanie(int ile_liczb) //dodawanie
  20. {
  21. int q, w, e;
  22. double czas;
  23. double sredni_czas=0;
  24. for(q=0;q<10;q++){
  25. losowanieLiczb();
  26. start=clock();
  27. for(w=0;w<ile_liczb;w++){
  28.  
  29. __asm( "flds a1\n"
  30. "fadds b1 \n"
  31. );
  32.  
  33.  
  34. }
  35. stop=clock();
  36. czas= (double)(stop-start)/CLOCKS_PER_SEC;
  37. sredni_czas= sredni_czas+czas;
  38. }
  39. return sredni_czas/10;
  40. }
  41.  
  42. double odejmowanie(int ile_liczb) //odejmowanie
  43. {
  44. int q, w;
  45. double czas;
  46. double sredni_czas=0;
  47. for(q=0;q<10;q++){
  48.  
  49. losowanieLiczb();
  50. start=clock();
  51. for(w=0;w<ile_liczb;w++){
  52.  
  53.  
  54.  
  55. //__asm( "movl $a1, %eax \n"
  56. // "movl $b1, %ebx \n"
  57. // "subl %ebx, %eax \n"
  58. //);
  59.  
  60.  
  61.  
  62. __asm( "flds a1\n"
  63. "fsubs b1 \n"
  64. );
  65.  
  66.  
  67. }
  68.  
  69. stop=clock();
  70. czas= (double)(stop-start)/CLOCKS_PER_SEC;
  71. sredni_czas= sredni_czas+czas;
  72. }
  73. return sredni_czas/10;
  74. }
  75.  
  76.  
  77.  
  78. double mnozenie(int ile_liczb) //mnozenie
  79. {
  80. int q, w;
  81. double czas;
  82. double sredni_czas=0;
  83. for(q=0;q<10;q++){
  84.  
  85. losowanieLiczb();
  86. start=clock();
  87. for(w=0;w<ile_liczb;w++){
  88.  
  89.  
  90.  
  91.  
  92. __asm( "flds a1\n"
  93. "fmuls b1 \n"
  94. );
  95.  
  96.  
  97. //__asm( "movl $a1, %eax \n"
  98. // "movl $b1, %ebx \n"
  99. // "mull %ebx, %eax \n"
  100. //);
  101.  
  102. //a1=a1*b1;
  103.  
  104. }
  105.  
  106. stop=clock();
  107. czas= (double)(stop-start)/CLOCKS_PER_SEC;
  108. sredni_czas= sredni_czas+czas;
  109. }
  110. return sredni_czas/10;
  111. }
  112.  
  113.  
  114. double dzielenie(int ile_liczb) //dzielenie
  115. {
  116. int q, w;
  117. double czas;
  118. double sredni_czas=0;
  119. for(q=0;q<10;q++){
  120. losowanieLiczb();
  121. start=clock();
  122. for(w=0;w<ile_liczb;w++){
  123.  
  124.  
  125. //__asm( "movl $a1, %eax \n"
  126. // "movl $b1, %ebx \n"
  127. // "divl %ebx, %eax \n"
  128. //);
  129.  
  130. __asm( "flds a1\n"
  131. "fmuls b1 \n"
  132. );
  133.  
  134.  
  135. }
  136.  
  137. stop=clock();
  138. czas= (double)(stop-start)/CLOCKS_PER_SEC;
  139. sredni_czas= sredni_czas+czas;
  140. }
  141. return sredni_czas/10;
  142. }
  143.  
  144. int main()
  145. {
  146. dodawanie(2048);
  147.  
  148.  
  149. printf("\nTyp obliczen: SISD\n");
  150. printf("Ilosc liczb: %i\n", 2048);
  151. printf("+= %f\n", dodawanie(2048));
  152. printf("-= %f\n", odejmowanie(2048));
  153. printf("*= %f\n", mnozenie(2048));
  154. printf("/= %f\n\n", dzielenie(2048));
  155.  
  156. printf("\nTyp obliczen: SISD\n");
  157. printf("Ilosc liczb: %i\n", 4096);
  158. printf("+= %f\n", dodawanie(4096));
  159. printf("-= %f\n", odejmowanie(4096));
  160. printf("*= %f\n", mnozenie(4096));
  161. printf("/= %f\n\n", dzielenie(4096));
  162.  
  163. printf("\nTyp obliczen: SISD\n");
  164. printf("Ilosc liczb: %i\n", 8192);
  165. printf("+= %f\n", dodawanie(8192));
  166. printf("-= %f\n", odejmowanie(8192));
  167. printf("*= %f\n", mnozenie(8192));
  168. printf(":= %f\n\n", dzielenie(8192));
  169.  
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement