logoalt Hacker News

chrkatoday at 2:57 PM1 replyview on HN

You're talking about the complexity of the Quicksort algorithm, whereas the article is about code generation.

Both versions sort the same data using the same algorithm. Just a tiny change in the source code caused Clang to generate different machine code.

Using different seed values - (srand(1), srand(2), srand(time(NULL))) essentially leads to the same result. With a good choice of pivot, Quicksort is very close to O(n log n) in practice, so that’s not the key factor here.

The interesting thing is that the generated machine code changes significantly.


Replies

Sardtoktoday at 3:11 PM

Look at the source, Luke!

It's just rand() in test.c

show 1 reply