Skip to content

Instantly share code, notes, and snippets.

@thedeemon
Created June 26, 2014 09:05
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 thedeemon/0c610024e2f04d5a7c24 to your computer and use it in GitHub Desktop.
Save thedeemon/0c610024e2f04d5a7c24 to your computer and use it in GitHub Desktop.
#include "stdafx.h"
#include <vector>
#include <stdio.h>
#include <atlcoll.h>
int _tmain(int argc, _TCHAR* argv[])
{
std::vector<int> data;
data.resize(10000000);
FILE *f = fopen("ints.dat", "rb");
if (!f) {
printf("can't open file");
return 1;
}
auto sz = fread(&data[0], 4, 10000000, f);
printf("sz=%d\n", sz);
fclose(f);
LARGE_INTEGER t0, t1, t2, fr;
CAtlMap<int, int> h;
QueryPerformanceCounter(&t0);
for(int i=0; i<data.size(); i++) {
int x = data[i];
auto pair = h.Lookup(x);
if (pair==NULL)
h[x] = 1;
else
pair->m_value++;
//h[data[i]]++;
}
QueryPerformanceCounter(&t1);
int v = 0;
for(int i=0; i<data.size(); i++)
v ^= h[data[i]];
QueryPerformanceCounter(&t2);
QueryPerformanceFrequency(&fr);
double dt1 = (double)(t1.QuadPart - t0.QuadPart) / fr.QuadPart;
double dt2 = (double)(t2.QuadPart - t1.QuadPart) / fr.QuadPart;
printf("v=%d make=%lf read=%lf\n", v, dt1, dt2);
for(int i=0;i<4;i++)
printf("%d %d\n", data[i], h[data[i]]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment