Advertisement
neongm

Untitled

Mar 12th, 2021
888
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.44 KB | None | 0 0
  1. #include <chrono>
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5. #include <list>
  6.  
  7. class book
  8. {
  9. private:
  10.     size_t id;
  11.     std::vector<std::string> tags;
  12.     std::vector<std::string> load;
  13.     std::string description;
  14.     std::string src_link;
  15.  
  16. public:
  17.     void set_defaults(size_t _size)
  18.     {
  19.         tags = { "war", "peace", "nove", "tolstoy", "example", "example" , "example" , "example" , "example" , "example" , "example" , "example" };
  20.         description = "Роман-эпопея, описывающий представителей высшего дворянского сословия, оказавшихся в плену любовного треугольника. Переживая множество испытаний, каждый из героев переосмысливает свою жизнь и отношения с другими героями на фоне войны 1812 года, изменившей все общество";
  21.        
  22.         for (size_t i = 0; i < _size; i++) load.push_back(description);
  23.  
  24.         src_link = "https://ilibrary.ru/text/11/index.html";
  25.     }
  26.  
  27.     book() { set_defaults(1); }
  28.  
  29.     book(size_t _id, size_t _size = 4)
  30.     {
  31.         id = _id;
  32.         set_defaults(_size);
  33.     }
  34. };
  35.  
  36.  
  37. template<typename T>
  38. size_t timed_test_big_struct(T cont, size_t amount, size_t pos = 0, size_t load = 1)
  39. {
  40.     size_t time;
  41.     size_t aa = 2;
  42.     auto begin = std::chrono::steady_clock::now();
  43.    
  44.     for (size_t i = 0; i < amount; i++)
  45.     {
  46.         book buk = book(i, load);
  47.         cont.insert(cont.begin()+pos, buk);
  48.         //cont.push_back(buk);
  49.     }
  50.  
  51.     auto end = std::chrono::steady_clock::now();
  52.     time = std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count();
  53.     return time;
  54. }
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61. int main()
  62. {
  63.     std::cout << "Hello World!\n";
  64.  
  65.     size_t amount = 500;
  66.     size_t pos = 0;
  67.     std::vector<book> vec(amount);
  68.     std::list<book> list(amount);
  69.  
  70.    
  71.     std::cout << "\nload: 100\npos = 0\n";
  72.     size_t t1 = timed_test_big_struct(vec, amount, pos, 100);
  73.     size_t t2 = timed_test_big_struct(list, amount, pos, 100);
  74.  
  75.     std::cout << t1 << "ms - vec\n";
  76.     std::cout << t2 << "ms - list\n";
  77.    
  78.  
  79.     std::cout << "\nload: 10\npos = 0\n";
  80.     t1 = timed_test_big_struct(vec, amount, pos, 10);
  81.     t2 = timed_test_big_struct(list, amount, pos, 10);
  82.  
  83.     std::cout << t1 << "ms - vec\n";
  84.     std::cout << t2 << "ms - list\n";
  85.  
  86.     std::cout << "\nload: 0\npos = 0\n";
  87.     t1 = timed_test_big_struct(vec, amount, pos, 0);
  88.     t2 = timed_test_big_struct(list, amount, pos, 0);
  89.    
  90.     std::cout << t1 << "ms - vec\n";
  91.     std::cout << t2 << "ms - list\n";
  92.  
  93.  
  94.     // HIGHER LOAD
  95.  
  96.     pos = 250;
  97.  
  98.     std::cout << "\nload: 100\npos = 250\n";
  99.     t1 = timed_test_big_struct(vec, amount, pos, 100);
  100.     t2 = timed_test_big_struct(list, amount, pos, 100);
  101.  
  102.     std::cout << t1 << "ms - vec\n";
  103.     std::cout << t2 << "ms - list\n";
  104.  
  105.  
  106.     std::cout << "\nload: 10\npos = 250\n";
  107.     t1 = timed_test_big_struct(vec, amount, pos, 10);
  108.     t2 = timed_test_big_struct(list, amount, pos, 10);
  109.  
  110.     std::cout << t1 << "ms - vec\n";
  111.     std::cout << t2 << "ms - list\n";
  112.  
  113.     std::cout << "\nload: 0\npos = 250\n";
  114.     t1 = timed_test_big_struct(vec, amount, pos, 0);
  115.     t2 = timed_test_big_struct(list, amount, pos, 0);
  116.  
  117.     std::cout << t1 << "ms - vec\n";
  118.     std::cout << t2 << "ms - list\n";
  119.     return 0;
  120.  
  121. }
  122.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement