Skip to content

Instantly share code, notes, and snippets.

@evilmucedin
Created August 30, 2016 10:37
Show Gist options
  • Save evilmucedin/932b92c1532a18753f5f674b4434d4d4 to your computer and use it in GitHub Desktop.
Save evilmucedin/932b92c1532a18753f5f674b4434d4d4 to your computer and use it in GitHub Desktop.
// g++ -O3 Spaces.cpp -o Spaces --std=c++14 -march=native -g; time ./Spaces
#include <iostream>
#include <string>
using namespace std;
static string InjectSpaces(const string& s) {
string result(2*s.length() - 1, ' ');
const auto length = s.length();
for (auto i = 0; i < length; ++i) {
result[2*i] = s[i];
}
return result;
}
int main() {
string s = "1234567890";
string result;
for (size_t i = 0; i < 200000000; ++i) {
result = InjectSpaces(s);
}
cout << result << endl;
return 0;
}
@dkorolev
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment