Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

21 May, 2024: Computers section is temporarily disabled for maintenance. It will take several days before it's back.


devel / comp.lang.tcl / Sorting a sorted list is inexpensive?

SubjectAuthor
* Sorting a sorted list is inexpensive?Cecil Westerhof
`* Re: Sorting a sorted list is inexpensive?Ralf Fassel
 `- Re: Sorting a sorted list is inexpensive?Cecil Westerhof

1
Sorting a sorted list is inexpensive?

<87jzy5zvif.fsf@munus.decebal.nl>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=21841&group=comp.lang.tcl#21841

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Cecil@decebal.nl (Cecil Westerhof)
Newsgroups: comp.lang.tcl
Subject: Sorting a sorted list is inexpensive?
Date: Fri, 21 Apr 2023 06:53:12 +0200
Organization: Decebal Computing
Lines: 22
Message-ID: <87jzy5zvif.fsf@munus.decebal.nl>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="e5ef67dbbe0efc0be3c6fb52d74300ff";
logging-data="1056190"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/yVoj4Fjg0YBCZJ93Iy4OaSLvV0OYF+4Q="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:w+7AQrK2vKRyiQP9hNTJV37TzEY=
sha1:DI5r1esydxvppxnu1McEagATJrQ=
 by: Cecil Westerhof - Fri, 21 Apr 2023 04:53 UTC

I have a variable history that is filled like:
{{#1682051497} {emacsclient --create-frame org/dummy.org &}}
{{#1682051113} {time thinHistory.tcl}}
{{#1682051041} ll}
.
.
.

I use:
return [lsort -decreasing -index 0 ${history}]

to return it sorted decreasing on the first element of the containing
lists.
It seems that when the sort is not necessary that the sort does not
take much time. Can I count on this, or could it be that it is not
always the case and is it better to add code to make sure it is only
sorted when it is necessary?

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Re: Sorting a sorted list is inexpensive?

<ygaa5z18vr6.fsf@akutech.de>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=21843&group=comp.lang.tcl#21843

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralfixx@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: Re: Sorting a sorted list is inexpensive?
Date: Fri, 21 Apr 2023 10:50:05 +0200
Lines: 28
Message-ID: <ygaa5z18vr6.fsf@akutech.de>
References: <87jzy5zvif.fsf@munus.decebal.nl>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net mKXIVNTThM2j7kIYPwcuYQ4KMdlcd4TWfRQXaBdRqvHn9Zwrc=
Cancel-Lock: sha1:xAWbLeUC0DsdcVDSNAuEZcxHglE= sha1:mCEDEqnxX3cnp7EHHIpLdHLj5ik=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
 by: Ralf Fassel - Fri, 21 Apr 2023 08:50 UTC

* Cecil Westerhof <Cecil@decebal.nl>
| I use:
| return [lsort -decreasing -index 0 ${history}]
>
| to return it sorted decreasing on the first element of the containing
| lists.
| It seems that when the sort is not necessary that the sort does not
| take much time. Can I count on this, or could it be that it is not
| always the case and is it better to add code to make sure it is only
| sorted when it is necessary?

man lsort(n)
The implementation of the lsort command uses the merge-sort
algorithm which is a stable sort that has O(n log n) performance
characteristics.

I read that merge-sort on an almost sorted list has good performance.
So as long as the algorithm of lsort is not changed...

But.
How much time max is it allowed to take before sorting becomes
noticeable? 1 second? 1 millisecond?

A history list sounds useful only if it does *not* contain zillions of
entries, and for anything less than say some hundred entries the time
for sorting it once should not be noticeable.

R'

Re: Sorting a sorted list is inexpensive?

<87bkjhzifk.fsf@munus.decebal.nl>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=21845&group=comp.lang.tcl#21845

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Cecil@decebal.nl (Cecil Westerhof)
Newsgroups: comp.lang.tcl
Subject: Re: Sorting a sorted list is inexpensive?
Date: Fri, 21 Apr 2023 11:35:43 +0200
Organization: Decebal Computing
Lines: 48
Message-ID: <87bkjhzifk.fsf@munus.decebal.nl>
References: <87jzy5zvif.fsf@munus.decebal.nl> <ygaa5z18vr6.fsf@akutech.de>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="e5ef67dbbe0efc0be3c6fb52d74300ff";
logging-data="1136442"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX191x4MSxNSv3uKx7ElKeIe+0J2sC0xmUws="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:uCzwyvmA0LSjrXSAxchtPrsGCHM=
sha1:y4sjhpGYwn2b2dzh5KwnOXDlAJ8=
 by: Cecil Westerhof - Fri, 21 Apr 2023 09:35 UTC

Ralf Fassel <ralfixx@gmx.de> writes:

> * Cecil Westerhof <Cecil@decebal.nl>
> | I use:
> | return [lsort -decreasing -index 0 ${history}]
>>
> | to return it sorted decreasing on the first element of the containing
> | lists.
> | It seems that when the sort is not necessary that the sort does not
> | take much time. Can I count on this, or could it be that it is not
> | always the case and is it better to add code to make sure it is only
> | sorted when it is necessary?
>
> man lsort(n)
> The implementation of the lsort command uses the merge-sort
> algorithm which is a stable sort that has O(n log n) performance
> characteristics.
>
> I read that merge-sort on an almost sorted list has good performance.
> So as long as the algorithm of lsort is not changed...

Well, when only one element was out of order, the program took about
three times as long to execute. But when none where out of order it
took about the same time with, or without sort.

> But.
> How much time max is it allowed to take before sorting becomes
> noticeable? 1 second? 1 millisecond?

In this case it is not something to worry about, but I like to learn
things I do not need right away. :-D

> A history list sounds useful only if it does *not* contain zillions of
> entries, and for anything less than say some hundred entries the time
> for sorting it once should not be noticeable.

The one I tested it on had about 150. I know that thousands are not
uncommon and that there are people who use tens of thousands.

Thanks. I keep it without extra code.

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof


devel / comp.lang.tcl / Sorting a sorted list is inexpensive?

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor