News for hackers. Stuff that matters.
Re:FreeBSD replaces bubblesort with mergesort on SYSINTs, re... by eru on Monday August 21, 2023 @12:14PM (#37211589)
If you find yourself having to re-implement a sorting algorithm ad-hoc, you are probably using the wrong language. (Especially these days.)
Re:FreeBSD replaces bubblesort with mergesort on SYSINTs, re... by kstrauser on Monday August 21, 2023 @02:21PM (#37213370)
...or you're implementing a kernel and don't have full access to a libc.
Re:FreeBSD replaces bubblesort with mergesort on SYSINTs, re... by eru on Monday August 21, 2023 @02:36PM (#37213576)
Who says you have to use libc?

Eg Rust has no-std crates that you can use even if you can't use the standard library.

Re:FreeBSD replaces bubblesort with mergesort on SYSINTs, re... by mort96 on Monday August 21, 2023 @03:50PM (#37214447)
What language should they have used instead of C?

And given that C's stdlib has a quicksort function, how would using a different language have helped?

Re:FreeBSD replaces bubblesort with mergesort on SYSINTs, re... by eru on Monday August 21, 2023 @03:52PM (#37214467)
Back then C might have been the best bet.
Re:FreeBSD replaces bubblesort with mergesort on SYSINTs, re... by kragen on Monday August 21, 2023 @10:30PM (#37217908)
i think it's pretty common for a specialized reimplementation of a standard library type or function to outperform it by an order of magnitude or so in some particular case. chris wellons gave an excellent example of this with hashing in golang in https://nullprogram.com/blog/2023/06/26/

commonly (as in wellons's post about the two-sum problem) there's a variation on the standard algorithm that can help significantly, but which the standard library function doesn't have an option for

also i think the cost of reimplementing simple 'algorithms from the book' like insertion sort or even quicksort is pretty low; as you saw in my comment above, insertion sort is six lines of code and only moderately bug-prone. we aren't talking about fibonacci heaps or red-black trees or fm-indexes or rader's algorithm or something. the cost is low enough that it's easy to justify in a lot of cases