faster replacement for `sort ... | head`