Sign in to follow this  
Followers 0
randallc

Array sort in scriptcontrol8-10x faster than _arraySort on 1D.

2 posts in this topic

#1 ·  Posted (edited)

Hi,

I have the 1D sort working, and it is 8-10x faster than _arraySort on 1D. [ ** Numeric and case-sensitive only at present.....], and reported slower than Clib sort if long strings...

The 2D is a lot slower than my vbs sort routine (already 6x faster than _ArraySort); unless there is a way I don't know; looks like jscript does not use same fast sort for 2D (its 2D arrays are arrays of single arrays essentially! - I think!)

Best, randall

; jscript3.au3
#include-once
#Include <Array.au3>
Global $arr1D = StringSplit("19274948","")
_ArrayDisplay($arr1D,"$arr1D unsorted")
Global $arr2D[6][4] = [["a0", "b3", "c9", "1"], ["a0", "b1", "c3", "11"], ["a0", "b2", "c2", "3"], ["a0", "b0", "c8", "0"], ["a4", "b4", "c7", "5"], ["a5", "5", "5", "4"]]
_ArrayDisplay($arr2D,"$arr2D unsorted")
_JSort1D($arr1D)
_ArrayDisplay($arr1D,"$arr1D sorted")
_JSort2D($arr2D)
_ArrayDisplay($arr2D,"$arr2D sorted")
Func _JSort1D(ByRef $arEither2D1D)
    Local $code = '   function SortArray(arrArray) {'
    $code &= @LF & '            return arrArray.toArray().sort().join("|");'
    $code &= @LF & '        }'
    Local $jvs = ObjCreate("ScriptControl")
    $jvs.language = "jscript"
    $jvs.Timeout = -1
    $jvs.addcode ($code)
;~  FileWrite(@ScriptDir & "\subsortIntroau3a.jvs", $code)
    Local $arEither2D1DSt = $jvs.Run("SortArray", $arEither2D1D);, $iIndex, $icase)
    $arEither2D1D = StringSplit($arEither2D1DSt, "|")
    $jvs = ""
EndFunc   ;==>_JSort1D
; Edited by randallc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

hi,

Nutster has a good review of programming in a series of functions in a new thread;

Sorting Functions

I have moved my extra sort tests here from there, and used some of his funcs for comparison.

vbs sort specifically for numbers and case sensitive is probably better value overall for 1D. [strings case insensitive not tested yet, and will obviously be slower overall]

Best, Randall

Sorts_TestRJC.zip

Edited by randallc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0