#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SIZE 32768
#define REP 20000
static int cmp(const void *x, const void *y){ return *(const int*)x - *(const int*)y; }
static double now(void){ struct timespec t; clock_gettime(CLOCK_MONOTONIC,&t); return t.tv_sec+t.tv_nsec/1e9; }
static long run(const int *data){
    long sum = 0;
    for (int r = 0; r < REP; r++)
        for (int i = 0; i < SIZE; i++)
            if (data[i] >= 128) sum += data[i];
    return sum;
}
int main(void){
    static int data[SIZE];
    srand(1);
    for (int i = 0; i < SIZE; i++) data[i] = rand() % 256;
    double t0 = now(); long s1 = run(data); double t1 = now();
    qsort(data, SIZE, sizeof(int), cmp);
    double t2 = now(); long s2 = run(data); double t3 = now();
    printf("qarisiq: %.2f s, sirali: %.2f s, cem eyni? %s\n", t1-t0, t3-t2, s1==s2 ? "beli" : "xeyr");
    return 0;
}
