Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Artemis: Proposed changes for increased performance #35

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions Reverse.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
46 changes: 28 additions & 18 deletions high_load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, int> test_map;
boost::container::stable_vector<int> 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<int, int> m;
bool BenchmarkRunner::runBenchmark() {
// Initialize random number generator with current time as seed
srand(static_cast<unsigned>(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<int, int> testMap;
boost::container::stable_vector<int> 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<int, int> m;
}

// Return true to indicate successful completion of the benchmark
return true;
}
Empty file modified post_test.sh
100755 → 100644
Empty file.