all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Andrew Cohen <acohen@ust.hk>
To: emacs-devel@gnu.org
Subject: Re: sorting in C
Date: Sun, 27 Feb 2022 07:54:09 +0800	[thread overview]
Message-ID: <87pmn9gp5q.fsf@ust.hk> (raw)
In-Reply-To: 83wnhlsm3m.fsf@gnu.org

Turns out porting the cpython version of timsort was easier than I
expected :) There remain a few things to do but mostly finished.

Here are some (slightly) improved benchmarks (orig = original mergesort;
vec = convert to vector and use existing vector sort; tim = convert to
vector and use timsort).  The numbers are microseconds.

Key: all lists are length=1000; in the first two rows the lists are
blocks of sorted sublists of length 100 and 10 respectively; next is a
list with the ith element= (logxor i 1); then a constant list, random
list, a sorted list with 3 random elements swapping position, reverse
sorted list, and finally a sorted list.

|                                    | orig | vec | tim |
|------------------------------------+------+-----+-----|
| (make-block-list 1000 100)         |  157 | 118 |  78 |
| (make-block-list 1000 10)          |  200 | 153 | 160 |
| (make-evil-list 1000)              |  117 |  82 |  89 |
| (make-constant-list 1000)          |  107 |  75 |  17 |
| (make-random-list 1000)            |  211 | 164 | 167 |
| (make-swapped-list 1000 3)         |  123 |  89 |  23 |
| (nreverse (make-sorted-list 1000)) |  109 |  77 |  17 |
| (make-sorted-list 1000)            |  107 |  73 |  17 |

You can see that its always significantly better than the existing list
mergesort. Its comparable to the existing vector sort for the more
random cases, and hugely better on the more sorted cases. It is exactly
the cpython algorithm so no surprise that it tracks the benchmarks that
others have performed on the cpython code.

I have a few questions that I'll ask in a subsequent post.

Best,
Andy

-- 
Andrew Cohen




  reply	other threads:[~2022-02-26 23:54 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
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 [this message]
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=87pmn9gp5q.fsf@ust.hk \
    --to=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.