From: Eli Zaretskii <eliz@gnu.org>
To: Andrew Cohen <acohen@ust.hk>
Cc: emacs-devel@gnu.org
Subject: Re: sorting in C
Date: Wed, 23 Feb 2022 14:34:12 +0200 [thread overview]
Message-ID: <835yp5u5h7.fsf@gnu.org> (raw)
In-Reply-To: <8735kakymb.fsf@ust.hk> (message from Andrew Cohen on Wed, 23 Feb 2022 12:14:52 +0800)
> From: Andrew Cohen <acohen@ust.hk>
> Date: Wed, 23 Feb 2022 12:14:52 +0800
>
> | | old | new |
> |------------+-------+-------|
> | s63 | 1.485 | .376 |
> | s65 | 1.211 | .990 |
> | r63 | 1.323 | .609 |
> | r65 | 1.422 | 1.091 |
> | rand63 | 1.236 | 2.581 |
> | rand65 | 1.627 | 1.238 |
> | worst63 | 1.109 | 6.019 |
> | worst65 | 1.359 | 1.067 |
> | random100K | 160 | 101 |
>
>
> Observations: It all looks as expected. Its compatible with everything
> I have seen in similar comparisons you can find in the ether.
>
> Insertion sort: great for ordered lists (factor of 2 to 4 better);
> poor for random data (factor of 2 worse); worst case is 5.4 times
> worse (theoretical it should be about 32/6 = 5.333 :) ).
>
> Vector sort: its typically 30% faster, but does even better for longer
> lists.
>
> Is the insertion sort for small lists worth it compared to the vector
> sort? For partially ordered lists its between 2 and 4 times faster than
> the vector sort. For random data its a factor of 2 slower. The worst
> case is a factor of 6. I think its worth it (my prejudice is the data is
> more likely to be partially ordered than not.) Also the advantage of
> the insertion sort shown here is really the worst case---its more
> advantageous for even shorter lists where the overhead of converting to
> and from the list becomes more important.
The 5-fold slowdown is a pain, IMO. Can we do better in the worst
case?
> And implementing TIMSORT will be even better---similar or better speedup
> for the best cases, and only marginal degradation of the worst. But I
> think even this small change here is a win.
Can we see the numbers? This sounds like a net win to me.
Thanks.
next prev parent reply other threads:[~2022-02-23 12:34 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-22 2:52 sorting in C Andrew Cohen
2022-02-22 12:30 ` Eli Zaretskii
2022-02-22 12:54 ` Andrew Cohen
2022-02-22 13:11 ` Eli Zaretskii
2022-02-23 4:14 ` Andrew Cohen
2022-02-23 12:34 ` Eli Zaretskii [this message]
2022-02-23 12:53 ` Andrew Cohen
2022-02-23 13:14 ` Eli Zaretskii
2022-02-23 13:52 ` Andrew Cohen
2022-02-23 14:06 ` Andrew Cohen
2022-02-23 14:18 ` Eli Zaretskii
2022-02-26 23:54 ` Andrew Cohen
2022-02-27 2:27 ` Andrew Cohen
2022-02-27 7:28 ` Eli Zaretskii
2022-02-27 9:11 ` Andrew Cohen
2022-02-27 9:29 ` Eli Zaretskii
2022-02-27 10:42 ` Andrew Cohen
2022-03-04 0:13 ` Andrew Cohen
2022-03-04 7:05 ` Eli Zaretskii
2022-02-23 13:19 ` Yuri Khan
2022-02-23 14:12 ` Andrew Cohen
2022-02-22 13:12 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=835yp5u5h7.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=acohen@ust.hk \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.