Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- time_t start, stop;
- float a1;
- float b1;
- void losowanieLiczb() //uzupelnianie wektora liczbami
- {
- int przedzial1=1000;
- float przedzial2 = 4.12;
- srand(time(NULL));
- a1 = rand()%przedzial1/przedzial2;
- b1 = rand()%przedzial1/przedzial2;
- }
- double dodawanie(int ile_liczb) //dodawanie
- {
- int q, w, e;
- double czas;
- double sredni_czas=0;
- for(q=0;q<10;q++){
- losowanieLiczb();
- start=clock();
- for(w=0;w<ile_liczb;w++){
- __asm( "flds a1\n"
- "fadds b1 \n"
- );
- }
- stop=clock();
- czas= (double)(stop-start)/CLOCKS_PER_SEC;
- sredni_czas= sredni_czas+czas;
- }
- return sredni_czas/10;
- }
- double odejmowanie(int ile_liczb) //odejmowanie
- {
- int q, w;
- double czas;
- double sredni_czas=0;
- for(q=0;q<10;q++){
- losowanieLiczb();
- start=clock();
- for(w=0;w<ile_liczb;w++){
- //__asm( "movl $a1, %eax \n"
- // "movl $b1, %ebx \n"
- // "subl %ebx, %eax \n"
- //);
- __asm( "flds a1\n"
- "fsubs b1 \n"
- );
- }
- stop=clock();
- czas= (double)(stop-start)/CLOCKS_PER_SEC;
- sredni_czas= sredni_czas+czas;
- }
- return sredni_czas/10;
- }
- double mnozenie(int ile_liczb) //mnozenie
- {
- int q, w;
- double czas;
- double sredni_czas=0;
- for(q=0;q<10;q++){
- losowanieLiczb();
- start=clock();
- for(w=0;w<ile_liczb;w++){
- __asm( "flds a1\n"
- "fmuls b1 \n"
- );
- //__asm( "movl $a1, %eax \n"
- // "movl $b1, %ebx \n"
- // "mull %ebx, %eax \n"
- //);
- //a1=a1*b1;
- }
- stop=clock();
- czas= (double)(stop-start)/CLOCKS_PER_SEC;
- sredni_czas= sredni_czas+czas;
- }
- return sredni_czas/10;
- }
- double dzielenie(int ile_liczb) //dzielenie
- {
- int q, w;
- double czas;
- double sredni_czas=0;
- for(q=0;q<10;q++){
- losowanieLiczb();
- start=clock();
- for(w=0;w<ile_liczb;w++){
- //__asm( "movl $a1, %eax \n"
- // "movl $b1, %ebx \n"
- // "divl %ebx, %eax \n"
- //);
- __asm( "flds a1\n"
- "fmuls b1 \n"
- );
- }
- stop=clock();
- czas= (double)(stop-start)/CLOCKS_PER_SEC;
- sredni_czas= sredni_czas+czas;
- }
- return sredni_czas/10;
- }
- int main()
- {
- dodawanie(2048);
- printf("\nTyp obliczen: SISD\n");
- printf("Ilosc liczb: %i\n", 2048);
- printf("+= %f\n", dodawanie(2048));
- printf("-= %f\n", odejmowanie(2048));
- printf("*= %f\n", mnozenie(2048));
- printf("/= %f\n\n", dzielenie(2048));
- printf("\nTyp obliczen: SISD\n");
- printf("Ilosc liczb: %i\n", 4096);
- printf("+= %f\n", dodawanie(4096));
- printf("-= %f\n", odejmowanie(4096));
- printf("*= %f\n", mnozenie(4096));
- printf("/= %f\n\n", dzielenie(4096));
- printf("\nTyp obliczen: SISD\n");
- printf("Ilosc liczb: %i\n", 8192);
- printf("+= %f\n", dodawanie(8192));
- printf("-= %f\n", odejmowanie(8192));
- printf("*= %f\n", mnozenie(8192));
- printf(":= %f\n\n", dzielenie(8192));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement