<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Сортировка массива]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=18289&amp;type=atom" />
	<updated>2024-08-28T16:04:15Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=18289</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Сортировка массива]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=161540#p161540" />
			<content type="html"><![CDATA[<p>Да, странно, у меня вчера вроде показывало прирост. Но и от SetCapacity результат не особо значительный, у меня:<br />8300 - 8500<br />8100 - 8300<br />7600 - 7900</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2024-08-28T16:04:15Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=161540#p161540</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Сортировка массива]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=161539#p161539" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>SetBatchLines, -1

arr := []
arr.SetCapacity(100000000) 
Loop 100000 {
    Random, rand
    arr.Push({value: rand})
}

a := A_TickCount
SortDescending(arr, &quot;value&quot;)
msgbox % A_TickCount - a

a := A_TickCount
SortDescending1(arr, &quot;value&quot;)
msgbox % A_TickCount - a

a := A_TickCount
SortDescending2(arr, &quot;value&quot;)
msgbox % A_TickCount - a


SortDescending(arr, key, sort = &quot;R N&quot;, del = &quot;|&quot;) {
	res := [], ex := {}, str := &quot;&quot; 
	for k, v in arr {
		str .= v[key] del
		If !ex[v[key]]
			ex[v[key]] := []
		ex[v[key]].push(k)
	}
	Sort str, U D%del% Z %sort%
	Loop, Parse, str, %del%
	{
		for k, v in ex[A_LoopField]  
			res.push(arr[v])
	} 
	Return res 
}


SortDescending1(arr, key, sort = &quot;R N&quot;, del = &quot;|&quot;) {
	res := [], ex := {}, str := &quot;&quot; 
; res.SetCapacity(100000000) 
 VarSetCapacity(str, 100000000)
	for k, v in arr {
		str .= v[key] del
		If !ex[v[key]]
			ex[v[key]] := []
		ex[v[key]].push(k)
	}
	Sort str, U D%del% Z %sort%
	Loop, Parse, str, %del%
	{
		for k, v in ex[A_LoopField]  
			res.push(arr[v])
	} 
	Return res 
}

SortDescending2(arr, key, sort = &quot;R N&quot;, del = &quot;|&quot;) {
	res := [], ex := {}, str := &quot;&quot; 
 res.SetCapacity(100000000) 
; VarSetCapacity(str, 100000000)
	for k, v in arr {
		str .= v[key] del
		If !ex[v[key]]
			ex[v[key]] := []
		ex[v[key]].push(k)
	}
	Sort str, U D%del% Z %sort%
	Loop, Parse, str, %del%
	{
		for k, v in ex[A_LoopField]  
			res.push(arr[v])
	} 
	Return res 
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2024-08-28T15:35:52Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=161539#p161539</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Сортировка массива]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=161537#p161537" />
			<content type="html"><![CDATA[<p>Почему не ускорит? У меня раза в полтора ускоряет на большом массиве.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2024-08-28T14:42:52Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=161537#p161537</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Сортировка массива]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=161536#p161536" />
			<content type="html"><![CDATA[<p>Ну, сильно оно не ускорит.<br />res.SetCapacity() побольше ускорения даст.</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2024-08-28T13:16:33Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=161536#p161536</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Сортировка массива]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=161535#p161535" />
			<content type="html"><![CDATA[<p>Да, формирование строки. Я имел в виду ускорить пример с использованием Sort.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2024-08-28T09:08:47Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=161535#p161535</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Сортировка массива]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=161534#p161534" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>Кстати, чтобы ускорить использование Sort, нужно добавить VarSetCapacity.</p></blockquote></div><p>А с чем это связано, перед тем как попасть в Sort она ведь и так имеет нужный размер, а чтобы прикинуть размер, надо ещё раз массив перебрать. То есть массив перебирать и вычислять быстрее, чем при каждом добавлении в строку расширять её память. Если так то это не касается именно Sort, а это в общем так. Ну то есть не ускорить Sort, а ускорить формирование строки.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2024-08-28T08:37:58Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=161534#p161534</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Сортировка массива]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=161533#p161533" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>serzh82saratov пишет:</cite><blockquote><p>Пример можно</p></blockquote></div><div class="codebox"><pre><code>    VarSetCapacity(str, ...) ; здесь прикинуть, сколько может потребоваться
	for k, v in arr {
		str .= v[key] del
		If !ex[v[key]]
			ex[v[key]] := []
		ex[v[key]].push(k)
	}
	Sort str, U D%del% Z %sort%</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2024-08-27T19:51:12Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=161533#p161533</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Сортировка массива]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=161532#p161532" />
			<content type="html"><![CDATA[<p>Не, просто решил попробовать проверить с одинаковыми числами.<br /><a href="https://claude.ai/">https://claude.ai/</a></p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2024-08-27T17:05:20Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=161532#p161532</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Сортировка массива]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=161531#p161531" />
			<content type="html"><![CDATA[<p><strong>Malcev</strong><br />Это ты понял код, чтобы понять как сделать такой тест?</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2024-08-27T17:02:59Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=161531#p161531</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Сортировка массива]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=161530#p161530" />
			<content type="html"><![CDATA[<p>Эх, ё моё блин... Ху из &quot;Клод&quot;? Моне...</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2024-08-27T16:53:06Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=161530#p161530</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Сортировка массива]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=161529#p161529" />
			<content type="html"><![CDATA[<p>А с такими данными:<br /></p><div class="codebox"><pre><code>Loop 10000 {
    arr.Push({value: 1})
}</code></pre></div><p>в 1890 раз &quot;Клод&quot; тормознутее. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2024-08-27T16:28:21Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=161529#p161529</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Сортировка массива]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=161528#p161528" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>Кстати, чтобы ускорить использование Sort, нужно добавить VarSetCapacity</p></blockquote></div><p>Пример можно.</p><br /><p>На 1000 ключей оно уже в 3 раза проигрывает, так что тут надо ещё от задачи отталкиваться, для частого перебора небольших массивов не катит.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2024-08-27T15:41:59Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=161528#p161528</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Сортировка массива]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=161527#p161527" />
			<content type="html"><![CDATA[<p>Чем больше массив, тем больше проявляется польза алгоритма. Кстати, чтобы ускорить использование Sort, нужно добавить VarSetCapacity.<br /></p><div class="quotebox"><cite>serzh82saratov пишет:</cite><blockquote><p>Тут уже совсем другой код</p></blockquote></div><p>Это всё ещё QuickSort, который, насколько я помню, используется и в Sort. Но там есть разные модификации.<br /></p><div class="quotebox"><cite>serzh82saratov пишет:</cite><blockquote><p>Тут я так понял жпт постарался.</p></blockquote></div><p>Не, это был Клод. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2024-08-27T13:39:06Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=161527#p161527</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Сортировка массива]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=161525#p161525" />
			<content type="html"><![CDATA[<p>Но на 50000 ключей с Sort быстрее, на 60000 примерно вровень.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2024-08-27T13:12:08Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=161525#p161525</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Сортировка массива]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=161524#p161524" />
			<content type="html"><![CDATA[<p>Тут уже совсем другой код, опроверг сам себя что Sort не перебить.<br />4000 против 5500 с Sort, и против <strong>20000</strong> без Sort, не ожидал. </p><p>Тут я так понял жпт постарался. <img src="//forum.script-coding.com/img/smilies/wink.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2024-08-27T13:05:34Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=161524#p161524</id>
		</entry>
</feed>
