-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
80 lines (72 loc) · 2.36 KB
/
Copy pathmain.cpp
File metadata and controls
80 lines (72 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "source/ThreadPool.h"
#include "source/FutureHolder.h"
#include <iostream>
#include <functional>
#include <numeric>
#include <chrono>
#include <map>
#include <fstream>
bool end = false;
void TotalPrinter(std::shared_ptr<ElementsHolder> holder)
{
while (!end)
{
std::cout << "\rStat: " << holder->GetDoneCount() << "/" << holder->GetTotalCount() << " " << std::flush;
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
}
uint64_t Execute(std::function<void()> function, int times)
{
std::vector<std::chrono::milliseconds> time;
for (uint64_t i = 0; i < times; ++i)
{
auto now = std::chrono::steady_clock::now();
function();
time.emplace_back(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - now));
}
return std::accumulate(time.begin(), time.end(), std::chrono::milliseconds(0)).count() / time.size();
}
#include <mongocxx/client.hpp>
int main()
{
// std::map<uint64_t, uint64_t> times;
// for (uint64_t i = 4; i < 16; i += 2)
// {
// auto time = Execute([&i]()
// {
// auto holder = std::make_shared<ElementsHolder>(std::deque<uint64_t>{9, 6, 1, 1, 1, 1, 2}, 10, 7);
// auto holder = std::make_shared<ElementsHolder>(std::deque<uint64_t>{1, 2, 1}, 8, 3);
// end = false;
// std::thread t(&TotalPrinter, holder);
// ThreadPool pool(4, holder);
// pool.Execute();
// end = true;
// t.join();
mongocxx::instance ins;
mongocxx::client client(mongocxx::uri("mongodb://localhost:27017"));
auto res = client["Collatz"]["Collatz"].find_one({});
if (!res.has_value())
{
return 1;
}
for (auto i : res.get())
{
std::cout << i.key() << "\n";
}
// 2);
// std::cout << "Threads: " << i << ". Average time: " << time << " ms\n";
// times.emplace(time, i);
// }
// std::cout << "Min: " << times.begin()->first << " ms - " << times.begin()->second << " threads\n";
// // сохранять t для Цикла!!!
// auto errors = FutureHolder::instance().GetErrors();
// if (!errors.empty())
// {
// std::ofstream out("out", std::ios_base::out);
// for (const auto &error : errors)
// {
// out << error << "\n";
// }
// }
return 0;
}