Skip to content

Instantly share code, notes, and snippets.

@radiospiel
Created March 17, 2012 11:36
Show Gist options
  • Save radiospiel/2057852 to your computer and use it in GitHub Desktop.
Save radiospiel/2057852 to your computer and use it in GitHub Desktop.
#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