This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/21719] stdlib/msort : optimizing merge sort


https://sourceware.org/bugzilla/show_bug.cgi?id=21719

--- Comment #2 from Ayush Mittal <ayush.m at samsung dot com> ---
(1) Worst case when elements are already sorted.

#define N 100000000
long a[N];
int cmpfn (const void * a, const void * b)
{
   return ( *(long*)a - *(long*)b );
}

int main()
{
        long i;
        for (i=0;i<N;i++)
                a[i]=i;
        qsort(a, N, sizeof(long), cmpfn);
        for (i=1;i<N;i++)
        {
                if(a[i]<a[i-1])
                {
                        printf("Sorting failed\n");
                        break;
                }
        }
}

Tested on ARM:
Reading without patch :
# time ./qsort-test

real    0m22.011s
user    0m20.696s
sys     0m0.924s

Reading with patch :
# time ./qsort-test

real    0m3.797s
user    0m3.264s
sys     0m0.508s

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]