Advertisement
Guest User

Untitled

a guest
Jan 12th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. // ConsoleApplication1.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <time.h>
  8.  
  9.  
  10.  
  11.  
  12. int _tmain(int argc, _TCHAR* argv[])
  13. {
  14. int Array[1000], tmp, N;
  15.  
  16. N = 1000;
  17. for (int i = 0; i < 1000; i++)
  18. {
  19. Array[i] = rand()%1000;
  20. }
  21. tmp = 0;
  22.  
  23. clock_t begin, end;
  24. double time_spent;
  25. begin = clock();
  26. for (int i = 0; i < 999; i++)
  27. {
  28. for (int j = 0; j < 999; j ++)
  29. {
  30. if(Array[j] > Array [j+1])
  31. {
  32. tmp = Array[j];
  33. Array[j] = Array[j + 1];
  34. Array[j + 1] = tmp;
  35.  
  36. }
  37.  
  38. }
  39. }
  40. end = clock();
  41. time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
  42. printf(" Czas T1 c: %lf \n",time_spent);
  43.  
  44.  
  45.  
  46. for (int i = 0; i < 1000; i++)
  47. {
  48. Array[i] = rand()%1000;
  49. }
  50.  
  51.  
  52.  
  53.  
  54.  
  55. begin = clock();
  56. _asm{
  57. mov ECX, 1000
  58. xor EDI, EDI
  59. sortuj: mov ESI, 1000
  60. dec ESI
  61.  
  62. przesuwanie_elementow: mov EAX, Array[ESI*1]
  63. dec ESI
  64. cmp Array[ESI*1],EAX
  65. jge dalej
  66. zamiana: mov EDX, Array[ESI*1]
  67. mov Array[ESI*1 + 1], EDX
  68. mov Array[ESI*1], EAX
  69. dalej: cmp ESI,EDI
  70. ja przesuwanie_elementow
  71. inc EDI
  72. loop sortuj
  73.  
  74. };
  75. end = clock();
  76. time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
  77. printf(" Czas T2 asm: %lf \n",time_spent);
  78. system("PAUSE");
  79. return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement