# \[FMX\] Sort() function for Arrays

**URL:** <https://forum.kirupa.com/t/fmx-sort-function-for-arrays/42462>\
**Category:** flash\
**Created:** [February 9, 2004, 3:56pm UTC](https://forum.kirupa.com/t/fmx-sort-function-for-arrays/42462 "2004-02-09T15:56:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dots](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@Dots](https://forum.kirupa.com/u/Dots)\
**Post date:** [February 9, 2004, 3:56pm UTC](https://forum.kirupa.com/t/fmx-sort-function-for-arrays/42462/1 "2004-02-09T15:56:31Z")

</div>

Just a quick question about the sort() function for arrays in Flash MX. How efficient is it? I am currently developing a flash application that will need to read in hundreds of records from a database and sort them.

speed is crucial. Which is better? to use the built in sort() function or to create my own shell-sort?

I’m relatively new to actionscript, but i have strong experience developing (and sorting) in other languages.

Thanks,

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 9, 2004, 5:26pm UTC](https://forum.kirupa.com/t/fmx-sort-function-for-arrays/42462/2 "2004-02-09T17:26:18Z")

</div>

hmm well ive never used the sort function in flash but I believe it wouldn’t be to hard to create your own sort and then do a speed test between the two of them.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 9, 2004, 6:31pm UTC](https://forum.kirupa.com/t/fmx-sort-function-for-arrays/42462/3 "2004-02-09T18:31:31Z")

</div>

dots,

the built in sort is as fast as anything i’ve written, but that’s no reason not to give it a go! 😉

i wrote an array prototype to sort multi-dimensional arrays by a given index. it’s a “natural” sort meaning that it will sort to [1,3,12] rather than [1,12,3]. you can see it here:[http://proto.layer51.com/d.aspx?f=331](http://proto.layer51.com/d.aspx?f=331)

if speed is _really_ an issue, be warned: you hit flash’s ceiling pretty fast in terms of performance. you might consider doing the sorting in another application. serverside if it’s a web app and bandwidth is not anticipated to be a problem, or a java applet if you want to keep it all on the client side. i’d expect even javascript to be faster, but haven’t tried.

let us know!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 12, 2004, 5:36pm UTC](https://forum.kirupa.com/t/fmx-sort-function-for-arrays/42462/4 "2004-02-12T17:36:51Z")

</div>

I tested a few simple arrays and found that the built in sort(function) is actually quite powerful. Sorting small arrays resulted in no difference/inconclusive. however, after arrays of more than 2,000 records, the built-in sort() actually worked faster the the shell-sort method. (Being almost twice as fast with arrays of 10,000) records.

as i only need to sort arrays of no more than several fundred records, i’ll stick to the built-in sort as it seems just as good and easier to use.

thanks for your suggestions

Dots
