Last active
August 29, 2015 14:16
-
-
Save snoopspy/c37195d239f40ec045c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <map> | |
#include <cstdlib> | |
#include <iostream> | |
#include <string.h> | |
#include <VPerformanceElapsedTimer> | |
struct Key1 | |
{ | |
int a; | |
int b; | |
void randomize() | |
{ | |
a = rand(); | |
b = rand(); | |
} | |
bool operator < (const Key1& rhs) const | |
{ | |
if (a < rhs.a) return true; | |
if (a > rhs.a) return false; | |
if (b < rhs.b) return true; | |
return false; | |
} | |
}; | |
struct Key2 | |
{ | |
int a; | |
int b; | |
void randomize() | |
{ | |
a = rand(); | |
b = rand(); | |
} | |
bool operator < (const Key2& rhs) const | |
{ | |
return memcmp(this, &rhs, sizeof(Key2)) < 0; | |
} | |
}; | |
struct Key3 | |
{ | |
std::pair<int, int> pair; | |
void randomize() | |
{ | |
pair.first = rand(); | |
pair.second = rand(); | |
} | |
bool operator < (const Key3& rhs) const | |
{ | |
return pair < rhs.pair; | |
} | |
}; | |
struct Data | |
{ | |
int c; | |
void randomize() | |
{ | |
c = rand(); | |
} | |
}; | |
template <class KEY> | |
struct MapTest | |
{ | |
std::map<KEY, Data> map; | |
void prepare() | |
{ | |
for (int i = 0; i < 5000000; i++) | |
{ | |
KEY key; | |
key.randomize(); | |
Data data; | |
data.randomize(); | |
map[key] = data; | |
} | |
} | |
MapTest() | |
{ | |
VPerformanceElapsedTimer pfm; | |
pfm.check(1); | |
prepare(); | |
pfm.check(2); | |
pfm.report(std::cout); | |
} | |
}; | |
int main() | |
{ | |
delete new MapTest<Key1>; | |
delete new MapTest<Key2>; | |
delete new MapTest<Key3>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment