Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // oop2-lab3.cpp: определяет точку входа для консольного приложения.
- //
- #include "stdafx.h"
- #include <algorithm>
- #include <chrono>
- #include <deque>
- #include <functional>
- #include <iostream>
- #include <list>
- #include <map>
- #include <random>
- #include <vector>
- using namespace std;
- using namespace std::chrono;
- typedef time_point<system_clock, microseconds> timepoint;
- long long time_elapsed(timepoint begin, timepoint end) {
- return end.time_since_epoch().count() - begin.time_since_epoch().count();
- }
- template <class T, class F>
- void seq_test(T &container, F &f = [](int &i) {i++; }) {
- const type_info &ti = typeid(container);
- timepoint begin = time_point_cast<microseconds>(system_clock::now());
- for_each(begin(container), end(container), f);
- timepoint end = time_point_cast<microseconds>(system_clock::now());
- cout << "sequential access - " << ti.name << ": " << time_elapsed(begin, end) << " microseconds" << endl;
- }
- template <class T>
- void rand_test(T &container) {
- const type_info &ti = typeid(container);
- timepoint begin = time_point_cast<microseconds>(system_clock::now());
- try {
- for (int i = 0; i < size / 2; -1 * i, i++)
- ++container.at(i + size / 2);
- }
- catch (exception e) {
- cout << "random access - " << ti.name << ": no random access function" << endl;
- }
- timepoint end = time_point_cast<microseconds>(system_clock::now());
- cout << "random access - " << ti.name << ": " << time_elapsed(begin, end) << " microseconds" << endl;
- }
- int main()
- {
- const int size = 102400;
- deque<int> d(size);
- list<int> l;
- map<int, int> m;
- vector<int> v(size);
- for (int i = 0; i < size; i++) {
- d.at(i) = i;
- l.push_back(i);
- v.at(i) = i;
- m.emplace(i, i);
- }
- cout << "containers initialized" << endl;
- seq_test(d, [](int &i) {i++; });
- seq_test(l, [](int &i) {i++; });
- seq_test(m, [](pair<const int, int> &i) {i.second++; });
- seq_test(v, [](int &i) {i++; });
- rand_test(d);
- rand_test(l);
- rand_test(m);
- rand_test(v);
- timepoint ins_d_begin = time_point_cast<microseconds>(system_clock::now());
- d.insert(d.begin() + size / 2, v.at(0));
- timepoint ins_d_end = time_point_cast<microseconds>(system_clock::now());
- cout << "insert into the middle - deque: " << time_elapsed(ins_d_begin, ins_d_end) << " microseconds per element" << endl;
- auto it_l = l.begin();
- advance(it_l, distance(l.begin(), l.end()) / 2);
- timepoint ins_l_begin = time_point_cast<microseconds>(system_clock::now());
- for (int i = 0; i < size; i++)
- l.insert(it_l, v.at(i));
- timepoint ins_l_end = time_point_cast<microseconds>(system_clock::now());
- cout << "insert into the middle - list: " << time_elapsed(ins_l_begin, ins_l_end) << " microseconds" << endl;
- auto it_m = m.begin();
- advance(it_m, distance(m.begin(), m.end()) / 2);
- timepoint ins_m_begin = time_point_cast<microseconds>(system_clock::now());
- for (int i = 0; i < size; i++)
- m.insert(it_m, pair<int, int>(v.at(i), v.at(i)));
- timepoint ins_m_end = time_point_cast<microseconds>(system_clock::now());
- cout << "insert into the middle - map: " << time_elapsed(ins_m_begin, ins_m_end) << " microseconds" << endl;
- timepoint ins_v_begin = time_point_cast<microseconds>(system_clock::now());
- for (int i = 0; i < size; i++)
- v.insert(v.begin() + size / 2, v.at(i));
- timepoint ins_v_end = time_point_cast<microseconds>(system_clock::now());
- cout << "insert into the middle - vector: " << time_elapsed(ins_v_begin, ins_v_end) << " microseconds" << endl;
- system("pause");
- return 0;
- }
- Ошибка C2064 результатом вычисления фрагмента не является функция, принимающая 1 аргументов 28
- Ошибка C2672 "for_each": не найдена соответствующая перегруженная функция 28
- Ошибка C3867 "type_info::name": нестандартный синтаксис; используйте "&", чтобы создать указатель на член 30
- Ошибка C2563 несоответствие в списке формальных параметров 38
- Ошибка C2563 несоответствие в списке формальных параметров 39
- Ошибка C3867 "type_info::name": нестандартный синтаксис; используйте "&", чтобы создать указатель на член 42
- Ошибка C3867 "type_info::name": нестандартный синтаксис; используйте "&", чтобы создать указатель на член 45
- Ошибка C2039 at: не является членом "std::list<int,std::allocator<_Ty>>" 39
Advertisement
Add Comment
Please, Sign In to add comment