Sorting algorithms/Sleep sort: Difference between revisions

Content added Content deleted
m (Improved the formatting of the jq code (x2))
Line 1,015:
20 milliseconds is used to (try to) handle scheduler tick on Windows systems (around 15 ms). On Linux systems (after kernel 2.6.8), this value can be smaller.
 
<lang Oforth>funcimport: sleepSort(l)parallel
 
{
: sleepSort(l)
| ch n |
Channel new ->ch
l forEach: n [ #[ System sleep(n dup 20 *) sleep ch send(n) drop ] & ]
ListBuffer newSize(l size) #[ ch receive over add ] times(l size) ;</lang>
}</lang>
 
{{out}}
<pre>
sleepSort(100 seq 100 seq +) sleepSort println
[1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14,
14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 2