Skip to content

Instantly share code, notes, and snippets.

@na-ka-na
Created February 3, 2017 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save na-ka-na/c19b7e6e0bafdc45fbede14a9b3d39f3 to your computer and use it in GitHub Desktop.
Save na-ka-na/c19b7e6e0bafdc45fbede14a9b3d39f3 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;
static const unordered_map<int, int> mapA{};
int funcA(int key) {
auto f = mapA.find(key);
if (f == mapA.end()) {
return -9;
} else {
return f->second;
}
}
unordered_map<int, int> mapB{};
int funcB(int key) {
auto f = mapB.find(key);
if (f == mapB.end()) {
return -9;
} else {
return f->second;
}
}
int funcC(int key) {
static const unordered_map<int, int> map{};
auto f = map.find(key);
if (f == map.end()) {
return -9;
} else {
return f->second;
}
}
int funcD(int key) {
unordered_map<int, int> map{};
auto f = map.find(key);
if (f == map.end()) {
return -9;
} else {
return f->second;
}
}
int main(int argc, char** argv) {
char f = *argv[1];
int key = stoi(string(argv[2]));
int res = 0;
if (f == 'A') {
for (int i=0; i<100000000; ++i) {
res += funcA(key);
}
}
if (f == 'B') {
for (int i=0; i<100000000; ++i) {
res += funcB(key);
}
}
if (f == 'C') {
for (int i=0; i<100000000; ++i) {
res += funcC(key);
}
}
if (f == 'D') {
for (int i=0; i<100000000; ++i) {
res += funcD(key);
}
}
cout << res << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment