Skip to content

Instantly share code, notes, and snippets.

@chenshuo
Created May 13, 2012 02:45
Show Gist options
  • Save chenshuo/2671222 to your computer and use it in GitHub Desktop.
Save chenshuo/2671222 to your computer and use it in GitHub Desktop.
Sort 1GB integers
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
double getTime()
{
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec + tv.tv_usec / 1000000.0;
}
using namespace std;
int main()
{
double start = getTime();
vector<int> vec(1024*1024*1024/sizeof(int));
for (int i = 0; i < vec.size(); ++i)
vec[i] = lrand48();
printf("sorting %zd elements\n", vec.size());
double sorting = getTime();
sort(vec.begin(), vec.end());
double done = getTime();
printf("gen %f\n", sorting - start);
printf("sort %f\n", done - sorting);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment