04-05-2005, 06:12 AM
Using a pointers table as Angelo suggested and zstrings the result was 8.2 secs on my 1.8 athlon, now using the GDSL library + strcmp(), i got 5.2 secs (GDSL is a static lib, so the exe was 17kb, no DLL's are needed), here's the test:
Code:
#include once "gdsl/gdsl.bi"
#include once "crt.bi"
declare sub quicksort(byval min,byval max)
declare sub fillarray(byval min,byval max)
const elements = 3000000
dim shared myarray(0 to elements-1) as zstring * 8
dim shared ptrarray(0 to elements-1) as zstring ptr
'' using quicksort in FB
fillarray(0, elements-1)
t# = timer
quicksort(0, elements-1)
print timer - t#
'' using gdsl + strcmp
fillarray(0, elements-1)
t# = timer
gdsl_sort( @ptrarray(0), elements, @strcmp )
print timer - t#
'':::::
sub fillarray(byval min,byval max)
dim i as integer
dim s as string
for i = max to min step -1
s = str$(i)
if len(s) < 7 then
s += string$(7 - len(s), " ")
end if
myarray(max-i) = s
ptrarray(i) = @myarray(i)
next z
end sub
'':::::
sub quicksort(byval min,byval max)
dim p1,p2,midd as zstring*8
if min < max then
p1 = min
p2 = max
midd = *ptrarray((min + max) \ 2)
do until p1 > p2
do while *ptrarray(p1) < midd
p1 += 1
loop
do while midd < *ptrarray(p2)
p2 -= 1
loop
if p1 <= p2 then
swap ptrarray(p1), ptrarray(p2)
p1 += 1
p2 -= 1
end if
loop
if min < p2 then quicksort min, p2
if p1 < max then quicksort p1, max
end if
end sub
ew FreeBASIC forums: http://www.freebasic.net/forum/index.php