Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <chrono>
- #include <iostream>
- #include <string>
- #include <vector>
- #include <list>
- class book
- {
- private:
- size_t id;
- std::vector<std::string> tags;
- std::vector<std::string> load;
- std::string description;
- std::string src_link;
- public:
- void set_defaults(size_t _size)
- {
- tags = { "war", "peace", "nove", "tolstoy", "example", "example" , "example" , "example" , "example" , "example" , "example" , "example" };
- description = "Роман-эпопея, описывающий представителей высшего дворянского сословия, оказавшихся в плену любовного треугольника. Переживая множество испытаний, каждый из героев переосмысливает свою жизнь и отношения с другими героями на фоне войны 1812 года, изменившей все общество";
- for (size_t i = 0; i < _size; i++) load.push_back(description);
- src_link = "https://ilibrary.ru/text/11/index.html";
- }
- book() { set_defaults(1); }
- book(size_t _id, size_t _size = 4)
- {
- id = _id;
- set_defaults(_size);
- }
- };
- template<typename T>
- size_t timed_test_big_struct(T cont, size_t amount, size_t pos = 0, size_t load = 1)
- {
- size_t time;
- size_t aa = 2;
- auto begin = std::chrono::steady_clock::now();
- for (size_t i = 0; i < amount; i++)
- {
- book buk = book(i, load);
- cont.insert(cont.begin()+pos, buk);
- //cont.push_back(buk);
- }
- auto end = std::chrono::steady_clock::now();
- time = std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count();
- return time;
- }
- int main()
- {
- std::cout << "Hello World!\n";
- size_t amount = 500;
- size_t pos = 0;
- std::vector<book> vec(amount);
- std::list<book> list(amount);
- std::cout << "\nload: 100\npos = 0\n";
- size_t t1 = timed_test_big_struct(vec, amount, pos, 100);
- size_t t2 = timed_test_big_struct(list, amount, pos, 100);
- std::cout << t1 << "ms - vec\n";
- std::cout << t2 << "ms - list\n";
- std::cout << "\nload: 10\npos = 0\n";
- t1 = timed_test_big_struct(vec, amount, pos, 10);
- t2 = timed_test_big_struct(list, amount, pos, 10);
- std::cout << t1 << "ms - vec\n";
- std::cout << t2 << "ms - list\n";
- std::cout << "\nload: 0\npos = 0\n";
- t1 = timed_test_big_struct(vec, amount, pos, 0);
- t2 = timed_test_big_struct(list, amount, pos, 0);
- std::cout << t1 << "ms - vec\n";
- std::cout << t2 << "ms - list\n";
- // HIGHER LOAD
- pos = 250;
- std::cout << "\nload: 100\npos = 250\n";
- t1 = timed_test_big_struct(vec, amount, pos, 100);
- t2 = timed_test_big_struct(list, amount, pos, 100);
- std::cout << t1 << "ms - vec\n";
- std::cout << t2 << "ms - list\n";
- std::cout << "\nload: 10\npos = 250\n";
- t1 = timed_test_big_struct(vec, amount, pos, 10);
- t2 = timed_test_big_struct(list, amount, pos, 10);
- std::cout << t1 << "ms - vec\n";
- std::cout << t2 << "ms - list\n";
- std::cout << "\nload: 0\npos = 250\n";
- t1 = timed_test_big_struct(vec, amount, pos, 0);
- t2 = timed_test_big_struct(list, amount, pos, 0);
- std::cout << t1 << "ms - vec\n";
- std::cout << t2 << "ms - list\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement