Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. // Tablice.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <cstdlib>
  7. #include <string>
  8. #include <time.h>
  9. #include <algorithm>
  10. #include <vector>
  11. #include <Windows.h>
  12. #include <ctime>
  13. using namespace std;
  14. /*
  15. Dla 1k elementów czas wyniósł 133ms
  16. Dla 10k elementów czas wyniósł 1109ms
  17. Dla 100k elementów czas wyniósł 10488ms
  18. Dla 1mln elementów czas wyniósł 106828ms
  19. Dla 10mln elementów czas wyniósł 990203ms
  20. */
  21. double start() {
  22. double czas;
  23. czas = clock();
  24. return czas;
  25. }
  26.  
  27. double koniec(double start) {
  28. double czas;
  29. czas = clock() - start;
  30. return czas / CLOCKS_PER_SEC;
  31. }
  32.  
  33. int main()
  34. {
  35. double czas;
  36. int min = 20, max = -20;
  37. vector < int > tab;
  38. srand(time(NULL));
  39. czas = start();
  40. for (int i = 0; i < 10000000; i++) {
  41. tab.push_back(rand() % 41 - 20);
  42. cout << tab[i] << " ";
  43. if (min > tab[i])
  44. min = tab[i];
  45. if (max < tab[i])
  46. max = tab[i];
  47. }
  48. czas = koniec(czas);
  49. cout << endl;
  50. cout << "Tworzenie tablicy zajelo " << czas << " sekund" << endl;
  51. cout << "Max=" << max << endl;
  52. cout << "Min=" << min << endl;
  53.  
  54. system("PAUSE");
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement