Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template< typename T, typename Fun, typename ...Args>
- auto measure(Fun&& fun, Args&& ...args)
- {
- std::chrono::high_resolution_clock timer{};
- auto before = timer.now();
- fun(args...);
- auto after = timer.now();
- return std::chrono::duration_cast<T>((after - before));
- }
- // prosta struktura pomocnicza, pseudo tabelka
- class SimpleTable
- {
- public:
- std::vector<std::string> tuples;
- void addTuple(std::string tuple)
- {
- tuples.emplace_back(std::forward<std::string>(tuple));
- }
- void print()
- {
- for (auto& tuple : tuples)
- {
- std::cout << tuple << '\n';
- }
- }
- void toFile(std::string filename)
- {
- std::ofstream ofs{ "results\\" + filename };
- if (!ofs.is_open()) throw 15;
- for (auto& tuple : tuples)
- {
- ofs << tuple << '\n';
- }
- }
- };
- // rowniez wykorzystane do zad1_6
- void zad1_3()
- {
- SimpleTable sTable;
- sTable.print();
- sTable.addTuple("n;edgesSeq;edgesConc;");
- for (int i = 50; i <= 1000; i += 50)
- {
- std::ostringstream oss{};
- auto graph = blankGraph(i);
- gnp(graph.size(), 0.25f, graph);
- // ilość powtórzeń obliczeń do uśredniania
- const int STEPS = 10;
- long long seq = 0;
- long long conc = 0;
- for (int j = 0; j < STEPS; ++j)
- {
- seq += measure<std::chrono::nanoseconds>(countGraphEdgesSeq, graph.size(), graph).count();
- conc += measure<std::chrono::nanoseconds>(countGraphEdgesConc, graph.size(), graph).count();
- }
- oss
- << i << ';'
- // uśrednienie wyników
- << seq/STEPS << ';'
- << conc/STEPS << ';';
- // dodanie do prostej tabelki
- sTable.addTuple(oss.str());
- }
- // wyświetlenie w konsoli
- sTable.print();
- // zapisanie tabelki do pliku do obróbki w zewnętrznych programach
- sTable.toFile("zad1_3.txt");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement