Where can I find an experiments of arithmetic sorting functions of your forum ?
I made a port of Charles Hoar's QuickSort.
So, it's interesting to see something else to compare.
Code: Select all
@echo off
SetLocal EnableExtensions EnableDelayedExpansion
:: Set a count of numbers
set Count=30
:: Minimal and maximal numbers
set min=-100
set max=+100
:: Generation of numbers
for /L %%C in (1 1 %Count%) do set /a ar[%%C]=!random!%%(%max%-%min%+1)+%min%
echo Before:
call :PrintArray ar 1 %Count%
echo.
set t0=%time%
:: Sorting
call :qSort ar 1 %Count%
set t1=%time%
echo.
echo After:
call :PrintArray ar 1 %Count%
echo.
call :difftime
echo.
pause
exit /B
:qSort [arrayName] [lowBound] [upBound]
:: port of Charles Hoar QuickSort
:: maded by Alex Dragokas
set i=%2
set L=%3
set /a M=(%i%+%L%)/2
set M=!%1[%M%]!
:_qSort_m0
if %i% GTR %L% goto _qSort_m1
:_qSort_m2
if !%1[%i%]! GEQ %M% (goto _qSort_m3) else (set /a i+=1& goto _qSort_m2)
:_qSort_m3
if !%1[%L%]! LEQ %M% (goto _qSort_m4) else (set /a L-=1& goto _qSort_m3)
:_qSort_m4
if %i% GTR %L% goto _qSort_m5
set wsp=!%1[%i%]!
set %1[%i%]=!%1[%L%]!
set %1[%L%]=%wsp%
set /a i+=1, L-=1
:_qSort_m5
goto _qSort_m0
:_qSort_m1
if %2 LSS %L% call :qSort %1 %2 %L%
if %i% LSS %3 call :qSort %1 %i% %3
exit /B
:PrintArray [arrayName] [lowBound] [upBound]
For /L %%C in (%2 1 %3) do echo %1[%%C]=!%1[%%C]!
exit /B
:difftime
for /F "tokens=1-8 delims=:.," %%a in ("!t0: =0!:!t1: =0!") do set /a "a=(((1%%e-1%%a)*60)+1%%f-1%%b)*6000+1%%g%%h-1%%c%%d, a+=(a>>31) & 8640000, a*=10"
echo Elapsed: %a% msec.
goto :eof
Results on my system shows that the speed mostly depends on the number of elements of array.
Count: 100
Speed: 960 msec..
Count: 200
Speed: 2200 msec.
Count: 1000
Speed: 14520 msec.