Tag Archives: JS

Faster Array Sort in Javascript

Introduction :

Based on Eugene(inspirit) post about Faster Array Sort function in Flash, I ported his test code into javascript.
First of all, I’m mainly using JS for scripting into Adobe After Effects, Photoshop, … but not so much for web anyway. That being said I’m not a javascript guru, so bare with me if I did mistake, I took his code and just changed it a little bit so it would work in JS.

I still can’t make the “Flash Sort” (which seems to be the fastest one on AS) to work w/ JS. I don’t know what I’m doing wrong, if anyone has an idea ?

[UPDATE] Thx to MrDoob, “Flash Sort” works now !! I also add the check function and it seems some sorting still not working quite well.


Download Source Code :



Stats


Firefox

*******************************************
*******************************************
INFO
10 000 elements
User-agent header: Mozilla/5.0 (Windows; U; Windows NT 6.0; fr; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10 ( .NET CLR 3.5.30729; .NET4.0E)
——————————————————————–

JS BUILD IN SORT
Time : 18 ms
Sorting is OK
——————————————————————–

QUICK SORT + INSERTION SORT
Time : 9 ms
Sorting is wrong
——————————————————————–

3 WAY QUICK SORT
Time : 11 ms
Sorting is wrong
——————————————————————–

NON RECURSIVE QUICK SORT
Time : 15 ms
Sorting is OK
——————————————————————–

OPTIMIZED NON RECURSIVE QUICK SORT
Time : 16 ms
Sorting is OK
——————————————————————–

NON RECURSIVE QUICK SORT 2
Time : 13 ms
Sorting is OK
——————————————————————–

FLASH SORT
Time : 6 ms
Sorting is OK
——————————————————————–

IE 8

*******************************************
*******************************************
INFO
10 000 elements
User-agent header: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Tablet PC 2.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)
——————————————————————–

JS BUILD IN SORT
Time : 88 ms
Sorting is OK
——————————————————————–

QUICK SORT + INSERTION SORT
Time : 34 ms
Sorting is wrong
——————————————————————–

3 WAY QUICK SORT
Time : 47 ms
Sorting is wrong
——————————————————————–

NON RECURSIVE QUICK SORT
Time : 49 ms
Sorting is OK
——————————————————————–

OPTIMIZED NON RECURSIVE QUICK SORT
Time : 42 ms
Sorting is OK
——————————————————————–

NON RECURSIVE QUICK SORT 2
Time : 49 ms
Sorting is OK
——————————————————————–

FLASH SORT
Time : 30 ms
Sorting is OK
——————————————————————–

Chrome

*******************************************
*******************************************
INFO
10 000 elements
User-agent header: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.63 Safari/534.3
——————————————————————–

JS BUILD IN SORT
Time : 13 ms
Sorting is OK
——————————————————————–

QUICK SORT + INSERTION SORT
Time : 4 ms
Sorting is wrong
——————————————————————–

3 WAY QUICK SORT
Time : 3 ms
Sorting is wrong
——————————————————————–

NON RECURSIVE QUICK SORT
Time : 3 ms
Sorting is OK
——————————————————————–

OPTIMIZED NON RECURSIVE QUICK SORT
Time : 3 ms
Sorting is OK
——————————————————————–

NON RECURSIVE QUICK SORT 2
Time : 3 ms
Sorting is OK
——————————————————————–

FLASH SORT
Time : 3 ms
Sorting is OK
——————————————————————–

Adobe After Effects

*******************************************
*******************************************
INFO
10 000 elements
OS : Windows Vista 6.0 Service Pack 2
——————————————————————–
JS BUILD IN SORT
Time : 291 ms
Sorting is OK
——————————————————————–
QUICK SORT + INSERTION SORT
Time : 237 ms
Sorting is wrong
——————————————————————–
3 WAY QUICK SORT
Time : 251 ms
Sorting is wrong
——————————————————————–
NON RECURSIVE QUICK SORT
Time : 287 ms
Sorting is wrong
——————————————————————–
OPTIMIZED NON RECURSIVE QUICK SORT
Time : 250 ms
Sorting is wrong
——————————————————————–
NON RECURSIVE QUICK SORT 2
Time : 298 ms
Sorting is OK
——————————————————————–
FLASH SORT
Time : 281 ms
Sorting is wrong
——————————————————————–