Skip to content

Instantly share code, notes, and snippets.

@ahupowerdns
Created June 9, 2018 18:31
Show Gist options
  • Save ahupowerdns/0869aa466a970b6325d6e38d56e71f39 to your computer and use it in GitHub Desktop.
Save ahupowerdns/0869aa466a970b6325d6e38d56e71f39 to your computer and use it in GitHub Desktop.
#include <algorithm>
#include <vector>
#include <parallel/algorithm>
using namespace std;
extern "C" int cmp(const void* a, const void* b)
{
return *(int*)a < *(int*)b;
}
int main(int argc, char**argv)
{
auto lim = atoi(argv[1]);
vector<int> blah;
blah.reserve(lim);
for(int n=0 ; n < lim; ++n)
blah.push_back(random());
if(*argv[2]=='q')
qsort(&blah[0], blah.size(), sizeof(int), cmp);
else if(*argv[2]=='p')
__gnu_parallel::sort(blah.begin(), blah.end());
else if(*argv[2]=='s')
sort(blah.begin(), blah.end());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment