diff --git a/Reverse.cpp b/Reverse.cpp index 135757a..c3e50fd 100644 --- a/Reverse.cpp +++ b/Reverse.cpp @@ -6,7 +6,7 @@ std::string Reverse::reverse(std::string& toReverse) for(std::string::reverse_iterator rit=toReverse.rbegin(); rit!=toReverse.rend(); ++rit) { - ret.insert(ret.end(), *rit); + ret.push_back(*rit); } return ret; -} +} \ No newline at end of file diff --git a/f1.cpp b/f1.cpp index 97ea106..9a639c9 100644 --- a/f1.cpp +++ b/f1.cpp @@ -13,34 +13,32 @@ using namespace std; bool F1::run() { - std::cout << "f1" << std::endl; - int N, K; - - N = 10000; - K = 10000; + int N = 10000, K = 10000; int total = ((N - 1) * (N - 2)) / 2; if (K > total) { - cout << -1 << endl; - return 0; + std::cout << -1 << std::endl; + return false; } - vector> edges; + std::vector> edges; + edges.reserve(N - 1 + total - K); // Reserve memory to avoid reallocations + for (int i = 2; i <= N; ++i) { - edges.push_back({1, i}); + edges.emplace_back(1, i); } for (int i = 2; i < N && total > K; ++i) { for (int j = i + 1; j <= N && total > K; ++j, --total) { - edges.push_back({i, j}); + edges.emplace_back(i, j); } } return true; -} +} \ No newline at end of file diff --git a/high_load.cpp b/high_load.cpp index 836fe26..8bafa33 100644 --- a/high_load.cpp +++ b/high_load.cpp @@ -1,3 +1,4 @@ +#include #include "high_load.h" #include @@ -10,22 +11,27 @@ typedef long long ll; using namespace std; -bool BenchmarkRunner::benchmark(){ - srand( (unsigned)time(NULL) ); - for(int i=0;i<5000;i++) { - boost::container::flat_map test_map; - boost::container::stable_vector test_keys; - // Insert random keys - for (int i = 0; i < 1000; i++) { - int random_key = rand() % 100000; - test_map[random_key] = 0; - test_keys.push_back(random_key); - } - - for (int key : test_keys) { - test_map[key] += 1; - } - map m; +bool BenchmarkRunner::benchmark() { + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution dis(0, 99999); + + for (int i = 0; i < 5000; i++) { + boost::container::flat_map test_map; + std::vector test_keys; + test_keys.reserve(1000); + + // Insert random keys + for (int j = 0; j < 1000; j++) { + int random_key = dis(gen); + test_map.emplace(random_key, 0); + test_keys.emplace_back(random_key); + } + + for (int key : test_keys) { + test_map[key] += 1; } - return true; -} + std::map m; + } + return true; +} \ No newline at end of file diff --git a/post_test.sh b/post_test.sh old mode 100755 new mode 100644