Created
March 17, 2012 11:36
-
-
Save radiospiel/2057852 to your computer and use it in GitHub Desktop.
This file contains 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 <iostream> | |
#include <algorithm> | |
#include <vector> | |
#include "stop_watch.inl" // see https://gist.github.com/2057981 | |
#ifndef COUNT | |
#define COUNT 100000000 | |
#endif | |
int compare_int(const void* p1, const void* p2) | |
{ | |
int i1 = *(int*)p1; | |
int i2 = *(int*)p2; | |
return i1 < i2 ? -1 : i1 > i2 ? 1 : 0; | |
} | |
int main() | |
{ | |
srand(12345); | |
int* data1 = new int[COUNT]; | |
int* data2 = new int[COUNT]; | |
for(int i=0; i<COUNT; i++) { | |
data1[i] = data2[i] = ((rand() << 16) | rand()); | |
} | |
{ | |
StopWatch stopWatch("std::sort: "); | |
std::sort(data1, data1+COUNT); | |
} | |
{ | |
StopWatch stopWatch("qsort: "); | |
qsort(data2, COUNT, sizeof(int), compare_int); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment