Created
May 13, 2012 02:45
-
-
Save chenshuo/2671222 to your computer and use it in GitHub Desktop.
Sort 1GB integers
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 <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