Skip to content

Instantly share code, notes, and snippets.

@alwaysR9
Created April 13, 2020 09:05
Show Gist options
  • Save alwaysR9/fa0795a4fa67e10736c21a107f6cfdeb to your computer and use it in GitHub Desktop.
Save alwaysR9/fa0795a4fa67e10736c21a107f6cfdeb to your computer and use it in GitHub Desktop.
#include <iostream>
#include <unordered_map>
#include <vector>
#include <stdint.h>
#include <sys/time.h>
using namespace std;
int main() {
int x = 0;
unordered_map<int, int> m;
vector<int> v;
v.reserve(10240);
//uint64_t* z = new uint64_t[10000];
char* z = new char[10000];
timeval b, e;
gettimeofday(&b, NULL);
for (int i = 0; i < 10000; ++ i)
//x ++;
//m[i] = i;
//v.emplace_back(i);
//z[i] = i % 191;
z[i] = i;
gettimeofday(&e, NULL);
int diff = (e.tv_usec - b.tv_usec) + (e.tv_sec - b.tv_sec) * 1000000;
//cout << x << ", cost: " << diff << endl;
//cout << m.size() << ", cost: " << diff << endl;
//cout << v.size() << ", cost: " << diff << endl;
cout << z[100] << ", cost: " << diff << endl;
delete [] z;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment