Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <ctime>
  4. #include <vector>
  5. //#include <chrono> // for clock
  6. #include <thread> // for thread sleep
  7. using namespace std;
  8. using namespace std::chrono;
  9. using namespace std::this_thread;
  10.  
  11. #include "stack.h"
  12. #include "list.h"
  13.  
  14. int main()
  15. {

  16. int length = 1000;
  17. for(int y = 0; y < 3; y++){
  18.  
  19. int randArr[length];
  20. for( int i = 0; i < length; i++ ){
  21. randArr[i] = i;
  22. }
  23.  
  24. // Upg 1
  25. clock_t start;
  26. CStack theStack(length);
  27. start = std::clock();
  28. for (int i = 0; i < length; i++)
  29. {
  30. theStack.push(randArr[i]);
  31. }
  32.  
  33. double duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
  34. cout << "Stack time at length: " << length << " is " << duration << endl;
  35.  
  36. vector<long> theList; // Clist
  37. start = std::clock();
  38. for(int i = 0; i < length; i++){
  39. theList.push_back(randArr[i]); // change to insertFirst
  40. }
  41.  
  42. duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
  43. cout << "List time at length: " << length << " is " << duration << endl;
  44.  
  45. cout << "\n" << endl;
  46.  
  47. length = (length == 1000) ? 1000000 : 10000000;
  48.  
  49. }
  50.  
  51. system("pause");
  52. return 0 ;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement