HackerTrans
TopNewTrendsCommentsPastAskShowJobs

chrka

160 karmajoined l’année dernière
[email protected]

Submissions

Your code is fast – if you're lucky

tiki.li
119 points·by chrka·il y a 9 heures·77 comments

Your code is fast – if you're lucky

tiki.li
2 points·by chrka·il y a 18 jours·0 comments

Show HN: Faster than std:sort and pdqsort

easylang.online
1 points·by chrka·il y a 2 mois·0 comments

Show HN: Branchless Quicksort – faster than std:sort and pdqsort

easylang.online
2 points·by chrka·il y a 2 mois·0 comments

Show HN: Avoiding "if" makes Quicksort faster

easylang.online
3 points·by chrka·il y a 2 mois·4 comments

When 'if' slows you down, avoid it

easylang.online
6 points·by chrka·il y a 2 mois·0 comments

Show HN: A Fast Quicksort in C with Branch‑Avoidant Coding and Threads

easylang.online
1 points·by chrka·il y a 2 mois·0 comments

Show HN: Interactive demos of sorting algorithms with runtime comparisons

easylang.online
1 points·by chrka·il y a 3 mois·0 comments

Show HN: Interactive sorting algorithm visualizations with runtime comparisons

easylang.online
1 points·by chrka·il y a 3 mois·0 comments

Show HN: Law of Large Numbers or Why It's a Bad Idea to Go to a Casino

easylang.online
3 points·by chrka·il y a 6 mois·1 comments

Show HN: Programming a Christmas Tree

easylang.online
2 points·by chrka·il y a 7 mois·0 comments

Show HN: A short story of my programming language Easylang

easylang.online
2 points·by chrka·il y a 8 mois·0 comments

Analysis indicates that the universe’s expansion is not accelerating

ras.ac.uk
261 points·by chrka·il y a 8 mois·208 comments

Show HN: Strange Attractors – Visualized with Easylang

easylang.online
3 points·by chrka·il y a 8 mois·0 comments

Show HN: A beginner-programming language and IDE with helpful tab completion

easylang.online
3 points·by chrka·il y a 8 mois·0 comments

Splitting (Empty) Strings (2017)

chriszetter.com
1 points·by chrka·il y a 9 mois·0 comments

Show HN: Tab completion for my small browser-based programming language Easylang

easylang.online
2 points·by chrka·il y a 9 mois·0 comments

comments

chrka
·il y a 5 heures·discuss
Therefore it is srand(1).
chrka
·il y a 5 heures·discuss
Both versions use the same input data. I also tried different random initial values and got essentially the same result. I didn't test hundreds of inputs, since that would have been mostly a waste of time in this case. The algorithm and the data distribution remain practically the same. What I'm measuring is the machine code that Clang generates for the hot loop.
chrka
·il y a 5 heures·discuss
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.
chrka
·il y a 6 jours·discuss
Don't trust your compiler. Your code is only fast if you're lucky.

https://tiki.li/blog/lucky_code.html
chrka
·le mois dernier·discuss
Normally, quicksort works best on random data. But with 90% already sorted and 10% random, it actually becomes harder to pick a good pivot. Sometimes the pivot ends up too large, which creates very uneven splits. When that happens, the algorithm switches to heapsort to avoid worst-case behavior, but heapsort is slower. Now, instead of immediately switching, it tries to partition again. Only if it’s still bad does it fall back to heapsort. That’s why performance improves.
chrka
·le mois dernier·discuss
As for your party trick: The performance drop in "blqs" occurred because heapsort was applied directly to a poorly partitioned input. Quicksort now gets a second chance in this case. With 10% random, 90% sorted, the performance drop no longer occurs. It is now faster than std::sort.
chrka
·le mois dernier·discuss
You will now see the directory listing. This website was actually created for my primary side project: a simplified programming language for beginners. I just added a blog folder there for other things as well.
chrka
·le mois dernier·discuss
Branchful only wins via ILP when data becomes good predictable. But since Quicksort partitioning aims for a 50/50 split, it operates in the worst possible zone for a branch predictor. That's why branchless wins here, as proven by the benchmarks.
chrka
·le mois dernier·discuss
Author here. No, it's also called from the non_trivially_copyable branch (as a fallback). I'll fix that.
chrka
·il y a 7 mois·discuss
https://easylang.online/xmas.html