Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <ctime>
- #include <iomanip>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "rus");
- const long int TEST_TIME = pow(10, 9);
- double time1 = 0, time2 = 0, resultTime = 0;
- const int NUMBER_OF_ELEMENTS = 100000;
- const int COUNT_ROW = 1000;
- int COUNT_EL = NUMBER_OF_ELEMENTS / COUNT_ROW;
- int mass1[NUMBER_OF_ELEMENTS] = { 0 };
- int mass2[NUMBER_OF_ELEMENTS] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
- // Пустой цикл
- cout << "<<Пустой цикл>>" << endl;
- time1 = clock();
- for (int i = 1; i < TEST_TIME; i++)
- ;
- time2 = clock();
- resultTime = (time2 - time1)/CLOCKS_PER_SEC;
- if (((static_cast<int>(resultTime) >= 10) && (resultTime <= 20)) ||
- ((static_cast<int>(resultTime) % 10 >= 5) && (static_cast<int>(resultTime) % 10 <= 9)) ||
- (static_cast<int>(resultTime) % 10 == 0))
- cout << "Время выполнения " << resultTime << " секунд";
- else if (static_cast<int>(resultTime) % 10 == 1)
- cout << "Время выполнения " << resultTime << " секунда";
- else if ((static_cast<int>(resultTime) % 10 >= 2) && (static_cast<int>(resultTime) % 10 <= 4))
- cout << "Время выполнения " << resultTime << " секунды";
- cout << endl << "Time1 = " << time1 / CLOCKS_PER_SEC << "sec; time2 = " << time2 / CLOCKS_PER_SEC << "sec" << endl;
- // Регистровая адрессация
- cout << endl << "<<Регистровая адрессация>>" << endl;
- time1 = clock();
- for (int i = 1; i < TEST_TIME; i++)
- {
- _asm
- {
- add eax, ebx
- add eax, ebx
- add eax, ebx
- add eax, ebx
- add eax, ebx
- add eax, ebx
- add eax, ebx
- add eax, ebx
- add eax, ebx
- add eax, ebx
- }
- }
- time2 = clock();
- resultTime = (time2 - time1) / CLOCKS_PER_SEC;
- if (((static_cast<int>(resultTime) >= 10) && (resultTime <= 20)) ||
- ((static_cast<int>(resultTime) % 10 >= 5) && (static_cast<int>(resultTime) % 10 <= 9)) ||
- (static_cast<int>(resultTime) % 10 == 0))
- cout << "Время выполнения " << resultTime << " секунд";
- else if (static_cast<int>(resultTime) % 10 == 1)
- cout << "Время выполнения " << resultTime << " секунда";
- else if ((static_cast<int>(resultTime) % 10 >= 2) && (static_cast<int>(resultTime) % 10 <= 4))
- cout << "Время выполнения " << resultTime << " секунды";
- cout << endl << "Time1 = " << time1 / CLOCKS_PER_SEC << "sec; time2 = " << time2 / CLOCKS_PER_SEC << "sec" << endl;
- // Косвенно-регистровая адрессация reg,[]
- cout << endl << "<<Косвенно-регистровая адрессация reg,[]>>" << endl;
- time1 = clock();
- for (int i = 1; i < TEST_TIME; i++)
- {
- _asm
- {
- add eax, [ebx + edx * 4 + 8]
- add eax, [ebx + edx * 4 + 8]
- add eax, [ebx + edx * 4 + 8]
- add eax, [ebx + edx * 4 + 8]
- add eax, [ebx + edx * 4 + 8]
- add eax, [ebx + edx * 4 + 8]
- add eax, [ebx + edx * 4 + 8]
- add eax, [ebx + edx * 4 + 8]
- add eax, [ebx + edx * 4 + 8]
- add eax, [ebx + edx * 4 + 8]
- }
- }
- time2 = clock();
- resultTime = (time2 - time1) / CLOCKS_PER_SEC;
- if (((static_cast<int>(resultTime) >= 10) && (resultTime <= 20)) ||
- ((static_cast<int>(resultTime) % 10 >= 5) && (static_cast<int>(resultTime) % 10 <= 9)) ||
- (static_cast<int>(resultTime) % 10 == 0))
- cout << "Время выполнения " << resultTime << " секунд";
- else if (static_cast<int>(resultTime) % 10 == 1)
- cout << "Время выполнения " << resultTime << " секунда";
- else if ((static_cast<int>(resultTime) % 10 >= 2) && (static_cast<int>(resultTime) % 10 <= 4))
- cout << "Время выполнения " << resultTime << " секунды";
- cout << endl << "Time1 = " << time1 / CLOCKS_PER_SEC << "sec; time2 = " << time2 / CLOCKS_PER_SEC << "sec" << endl;
- // Косвенно-регистровая адрессация [],reg
- cout << endl << "<<Косвенно-регистровая адрессация [],reg>>" << endl;
- time1 = clock();
- _asm
- {
- mov esi, esp
- mov edi,1
- }
- for (int i = 1; i < TEST_TIME; i++)
- {
- _asm
- {
- add[esi + edi * 4 + 8], ebx
- add[esi + edi * 4 + 8], ebx
- add[esi + edi * 4 + 8], ebx
- add[esi + edi * 4 + 8], ebx
- add[esi + edi * 4 + 8], ebx
- add[esi + edi * 4 + 8], ebx
- add[esi + edi * 4 + 8], ebx
- add[esi + edi * 4 + 8], ebx
- add[esi + edi * 4 + 8], ebx
- add[esi + edi * 4 + 8], ebx
- }
- }
- time2 = clock();
- resultTime = (time2 - time1) / CLOCKS_PER_SEC;
- if (((static_cast<int>(resultTime) >= 10) && (resultTime <= 20)) ||
- ((static_cast<int>(resultTime) % 10 >= 5) && (static_cast<int>(resultTime) % 10 <= 9)) ||
- (static_cast<int>(resultTime) % 10 == 0))
- cout << "Время выполнения " << resultTime << " секунд";
- else if (static_cast<int>(resultTime) % 10 == 1)
- cout << "Время выполнения " << resultTime << " секунда";
- else if ((static_cast<int>(resultTime) % 10 >= 2) && (static_cast<int>(resultTime) % 10 <= 4))
- cout << "Время выполнения " << resultTime << " секунды";
- cout << endl << "Time1 = " << time1 / CLOCKS_PER_SEC << "sec; time2 = " << time2 / CLOCKS_PER_SEC << "sec" << endl;
- // 2.1
- cout << endl << "<<Ненаправленная адрессация>>" << endl;
- time1 = clock();
- _asm
- {
- mov esi, 0
- lea ebx, mass1
- e2:
- mov ecx, COUNT_EL
- mov eax, 10
- mov edx, esi
- and edx, 01h
- jz drop
- mov eax, 10
- e1:
- mov[ebx], eax
- add ebx, 4
- loop e1
- jmp outside
- drop:
- mov eax, 4
- mul COUNT_EL
- add ebx, eax
- jmp outside
- outside:
- add esi, 1
- mov eax, COUNT_ROW
- cmp eax, esi
- jg e2
- }
- time2 = clock();
- resultTime = (time2 - time1) / CLOCKS_PER_SEC;
- if (((static_cast<int>(resultTime) >= 10) && (resultTime <= 20)) ||
- ((static_cast<int>(resultTime) % 10 >= 5) && (static_cast<int>(resultTime) % 10 <= 9)) ||
- (static_cast<int>(resultTime) % 10 == 0))
- cout << "Время выполнения " << resultTime << " секунд";
- else if (static_cast<int>(resultTime) % 10 == 1)
- cout << "Время выполнения " << resultTime << " секунда";
- else if ((static_cast<int>(resultTime) % 10 >= 2) && (static_cast<int>(resultTime) % 10 <= 4))
- cout << "Время выполнения " << resultTime << " секунды";
- cout << endl << "Time1 = " << time1 / CLOCKS_PER_SEC << "sec; time2 = " << time2 / CLOCKS_PER_SEC << "sec" << endl;
- //cout << endl << "<<Массив mass1>>" << endl;
- //for (int i = 0; i < COUNT_ROW; i++)
- //{
- // for (int j = 0; j < COUNT_EL && i * COUNT_EL + j < NUMBER_OF_ELEMENTS; j++)
- // cout << setw(4) << mass1[i * COUNT_EL + j] << " ";
- // cout << endl;
- //}
- // 2.2
- cout << endl << "<<STOS>>" << endl;
- time1 = clock();
- _asm
- {
- mov esi, 0
- lea edi, mass2
- mov eax, 10
- met:
- mov ecx, COUNT_EL
- rep stos eax
- mov eax, 4
- mul COUNT_EL
- add edi, eax
- mov eax, COUNT_ROW
- add esi, 2
- cmp eax, esi
- jg met
- }
- time2 = clock();
- resultTime = (time2 - time1) / CLOCKS_PER_SEC;
- if (((static_cast<int>(resultTime) >= 10) && (resultTime <= 20)) ||
- ((static_cast<int>(resultTime) % 10 >= 5) && (static_cast<int>(resultTime) % 10 <= 9)) ||
- (static_cast<int>(resultTime) % 10 == 0))
- cout << "Время выполнения " << resultTime << " секунд";
- else if (static_cast<int>(resultTime) % 10 == 1)
- cout << "Время выполнения " << resultTime << " секунда";
- else if ((static_cast<int>(resultTime) % 10 >= 2) && (static_cast<int>(resultTime) % 10 <= 4))
- cout << "Время выполнения " << resultTime << " секунды";
- cout << endl << "Time1 = " << time1 / CLOCKS_PER_SEC << "sec; time2 = " << time2 / CLOCKS_PER_SEC << "sec" << endl;
- //cout << endl << "<<Массив mass2>>" << endl;
- //for (int i = 0; i < COUNT_ROW; i++)
- //{
- // for (int j = 0; j < COUNT_EL && i * COUNT_EL + j < NUMBER_OF_ELEMENTS; j++)
- // cout << setw(4) << mass2[i * COUNT_EL + j] << " ";
- // cout << endl;
- //}
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement