C - Is sorting an array of pointers of structs slower than sorting the structs directly (qsort) -
i sorting millions of structs organzied in array qsort-function of standard c library. tried optimize performance creating array of pointers of struct same length. in contrast expectations execution time of second variant slower:
qsort array of structs: 199s qsort array of pointers of structs: 204
i expected time swapping pointer blocks in memory faster moving structs (size 576). may have performance leaks or known behaviour?
there other issues here.
by creating array of pointers fragmenting memory. algorithms in standard libraries designed optimise sorting of contiguous arrays, doing missing cache far more if had bigger array.
quicksort in particular quite locality of reference, halve sample size , sorting subsets of original array in chunks can fit cache.
as general rule, cache misses order of magnitude slower hits. result time delay significant enough make speed not copying bytes.
Comments
Post a Comment