-
-
Save keller0/38d2449559ed8ab61762993e6c7f512e to your computer and use it in GitHub Desktop.
sort 1 billion integers in c
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<stdio.h> | |
#include<stdlib.h> | |
#include<time.h> | |
#define NOFA 1000000000 | |
int cmpfunc (const void * a, const void * b) { | |
return ( *(int*)a - *(int*)b ); | |
} | |
int main() | |
{ | |
float size = sizeof(int) * NOFA, s_t; | |
srand(time(NULL)); | |
s_t = clock(); | |
int * ap = malloc(size); | |
for(int i = 0 ; i < NOFA; i++ ) { | |
ap[i] = rand(); | |
} | |
printf("%f minuts to make array\n",(clock() - s_t)/CLOCKS_PER_SEC/60); | |
s_t = clock(); | |
qsort(ap, NOFA, sizeof(int), cmpfunc); | |
printf("%f minuts to sort array\n",(clock() - s_t)/CLOCKS_PER_SEC/60); | |
getchar(); | |
free(ap); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment