Last active
August 29, 2015 14:10
-
-
Save odashi/2fb40a9e032e85a177af to your computer and use it in GitHub Desktop.
mapのイテレーション速度を測定
This file contains hidden or 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 <random> | |
#include <iostream> | |
#include <cmath> | |
#include <sys/time.h> | |
using namespace std; | |
double mytime() { | |
timeval tv; | |
gettimeofday(&tv, NULL); | |
return tv.tv_sec + tv.tv_usec * 0.000001; | |
} | |
int main() { | |
random_device r; | |
for (int i = 0; i < 2000; ++i) { | |
map<int,int> m; | |
int jmax = (int)pow(1.01, i); | |
for (int j = 0; j < jmax; ++j) { | |
int k = r(); | |
while (m.find(k) != m.end()) k = r(); | |
m[k] = j; | |
} | |
volatile int sum = 0; | |
double begin = mytime(); | |
for (auto kv : m) ++sum; | |
double e = mytime() - begin; | |
cout << i << ' ' << sum << ' ' << e << ' ' << e/(double)sum << ' ' << endl; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment