This is, i hope, to be similar to WorkShop_Alex's challenge. The aim is to write the fastest sort possible with the following procedure:

sort(arraylength,arraymaxnum:integer); where arraylength is the length of the array and the arraymaxnum the largest integer possible in the array and the population of the array using:

Item := VarArrayCreate([0, arraylength], varInteger);

//POPULATE ARRAY

Randomize;

For X:=0 to arraylength do

begin

item[x]:=random(arraymaxnum);

end;

You must initiate the sort like so:

QueryPerformanceFrequency(freq); {Get counts/second}

QueryPerformanceCounter(start); {Get string count}

sort(10, 100) //values can be changed

Your sort must have showresult; at the end to get the details

The following unit has my testing procedure (we can configure thbis if it doesn't work properley) and my first sort algorithm for you guys to try and beat ;-). Currently my sort speed is approx 350 ticks.

unit Unit1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs;

type

TForm1 = class(TForm)

procedure FormCreate(Sender: TObject);

private

procedure sort(arraylength,arraymaxnum:integer);

procedure showresult;

public

start,stop1,freq:int64;

TotalTicks,NumASec: int64;

Ticksfor1,Timefor1: real;

end;

var

Form1: TForm1;

implementation

{$R *.dfm}

procedure tform1.showresult;

begin

QueryPerformanceCounter(Stop1); {Get end of loop2 count}

TotalTicks:= (stop1-start);

Timefor1:= TotalTicks / freq;

NumASec:= Trunc(1{second} / Timefor1);

If freq>0 then

showmessage('Sort took := '+

inttostr(TotalTicks)+

#13+' Ticks for 1 Call:= '+FloatToStrF(Ticksfor1,ffNumber, 6,3)+

#13+' Ticks per second:= '+inttostr(freq)+

#13+' Time in micro seconds (millionths) for 1 call:= '+FloatToStrF(1e6*Timefor1,ffNumber, 4,8))

else showmessage('No hardware timer available');

end;

procedure tform1.sort(arraylength, arraymaxnum:integer);

var Item:variant ;

X,y,temp:Integer;

result:string;

begin

Item := VarArrayCreate([0, arraylength], varInteger);

//POPULATE ARRAY

Randomize;

For X:=0 to arraylength do

begin

item[x]:=random(arraymaxnum);

end;

//SORT

Y:=-1;

X:=arraylength+1 ;

repeat

dec(x) ;

y:=-1;

repeat

inc(y) ;

if item[y]>item[x] then

begin

temp:=item[y];

item[y]:=item[x];

item[x]:=temp;

end;

until y>=x ;

until X<=0;

//End SORT

showresult;

For X:=0 to arraylength do

begin

result:=result + ' ' + inttostr(item[x]);

end;

showmessage(result);

end;

procedure TForm1.FormCreate(Sender: TObject);

begin

QueryPerformanceFrequency(freq); {Get counts/second}

QueryPerformanceCounter(start); {Get string count}

sort(10, 100)

end;

end.

Regards,

Hypoviax

1. 0-10

2. 0-100

3. 0-1000

4. 0-10000

My results with max integer of 100 (probably grossley slow ;-) ):

1. 345

2. 7642

3. 646902

4. 127752446

Hypoviax