From 751f132ec2d97d2f7c9c478258e0b435f4040d59 Mon Sep 17 00:00:00 2001 From: TurinTech Bot Date: Fri, 19 Jan 2024 15:20:38 +0000 Subject: [PATCH] Artemis Changes --- Reverse.cpp | 22 ++++++++++++++++------ high_load.cpp | 46 ++++++++++++++++++++++++++++------------------ post_test.sh | 0 3 files changed, 44 insertions(+), 24 deletions(-) mode change 100755 => 100644 post_test.sh diff --git a/Reverse.cpp b/Reverse.cpp index 135757a..3caed9a 100644 --- a/Reverse.cpp +++ b/Reverse.cpp @@ -1,12 +1,22 @@ #include "Reverse.h" -std::string Reverse::reverse(std::string& toReverse) + +/** + * This function reverses the order of characters in a given string. + * + * @param toReverse A reference to the string that needs to be reversed. + * @return A new string that is the reverse of the input string. + */ +std::string Reverse::reverse(const std::string& toReverse) { - std::string ret; + std::string reversedString; - for(std::string::reverse_iterator rit=toReverse.rbegin(); rit!=toReverse.rend(); ++rit) + // Iterate over the input string in reverse order + for(auto rit = toReverse.rbegin(); rit != toReverse.rend(); ++rit) { - ret.insert(ret.end(), *rit); + // Append each character to the end of the reversed string + reversedString.push_back(*rit); } - return ret; -} + + return reversedString; +} \ No newline at end of file diff --git a/high_load.cpp b/high_load.cpp index 836fe26..d70b929 100644 --- a/high_load.cpp +++ b/high_load.cpp @@ -10,22 +10,32 @@ 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::runBenchmark() { + // Initialize random number generator with current time as seed + srand(static_cast(time(nullptr))); + + // Perform 5000 iterations of the benchmark + for(int i = 0; i < 5000; i++) { + // Initialize a flat_map and a stable_vector from the Boost library + boost::container::flat_map testMap; + boost::container::stable_vector testKeys; + + // Insert 1000 random keys into the map and vector + for (int i = 0; i < 1000; i++) { + int randomKey = rand() % 100000; + testMap[randomKey] = 0; + testKeys.push_back(randomKey); + } + + // Increment the value of each key in the map + for (int key : testKeys) { + testMap[key] += 1; } - return true; -} + + // Unused map, consider removing if not needed + map m; + } + + // Return true to indicate successful completion of the benchmark + return true; +} \ No newline at end of file diff --git a/post_test.sh b/post_test.sh old mode 100755 new mode 100644