Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const
- RUNS = 10;
- RANGE_START = -9999;
- RANGE_FINISH = 9999;
- function TIAByRange8bit(aStart, aFinish: Integer): TIntArray;
- var
- g, h, i, t: Integer;
- begin
- if (aStart <> aFinish) then
- begin
- if (aStart > aFinish) then
- Swap(aStart, aFinish);
- h := (aFinish - aStart);
- g := (h div 8);
- SetLength(Result, (h + 1));
- for i := 0 to g do
- begin
- t := (i * 4);
- Result[t] := (aStart + t);
- Result[(t + 1)] := ((aStart + t) + 1);
- Result[(t + 2)] := ((aStart + t) + 2);
- Result[(t + 3)] := ((aStart + t) + 3);
- Result[((h - t) - 3)] := ((aFinish - t) - 3);
- Result[((h - t) - 2)] := ((aFinish - t) - 2);
- Result[((h - t) - 1)] := ((aFinish - t) - 1);
- Result[(h - t)] := (aFinish - t);
- end;
- if (((h + 1) mod 2) = 1) then
- Result[(t + 1)] := (aStart + (t + 1));
- end else
- Result := [aStart];
- end;
- function TIAByRange4bit(aStart, aFinish: Integer): TIntArray;
- var
- g, h, i, t: Integer;
- begin
- if (aStart <> aFinish) then
- begin
- if (aStart > aFinish) then
- Swap(aStart, aFinish);
- h := (aFinish - aStart);
- g := (h div 4);
- SetLength(Result, (h + 1));
- for i := 0 to g do
- begin
- t := (i * 2);
- Result[t] := (aStart + t);
- Result[(t + 1)] := ((aStart + t) + 1);
- Result[((h - t) - 1)] := ((aFinish - t) - 1);
- Result[(h - t)] := (aFinish - t);
- end;
- if (((h + 1) mod 2) = 1) then
- Result[(t + 1)] := (aStart + (t + 1));
- end else
- Result := [aStart];
- end;
- function TIAByRange2bit(aStart, aFinish: Integer): TIntArray;
- var
- g, h, i: Integer;
- begin
- if (aStart <> aFinish) then
- begin
- if (aStart > aFinish) then
- Swap(aStart, aFinish);
- h := (aFinish - aStart);
- g := (h div 2);
- SetLength(Result, (h + 1));
- for i := 0 to g do
- begin
- Result[i] := (aStart + i);
- Result[(h - i)] := (aFinish - i);
- end;
- if (((h + 1) mod 2) = 1) then
- Result[i] := (aStart + i);
- end else
- Result := [aStart];
- end;
- function TIAByRange(aStart, aFinish: Integer): TIntArray;
- var
- i: Integer;
- begin
- if (aStart <> aFinish) then
- begin
- if (aStart > aFinish) then
- Swap(aStart, aFinish);
- SetLength(Result, ((aFinish - aStart) + 1));
- for i := aStart to aFinish do
- Result[(i - aStart)] := i;
- end else
- Result := [aStart];
- end;
- var
- i, tm: Integer;
- tmp: TIntArray;
- tmr: array[0..3] of TIntArray;
- TSA: TStrArray;
- begin
- ClearDebug;
- TSA := ['TIAByRange', 'TIAByRange2bit', 'TIAByRange4bit', 'TIAByRange8bit'];
- for i := 0 to 3 do
- SetLength(tmr[i], RUNS);
- for i := 0 to (RUNS - 1) do
- begin
- tm := GetSystemTime;
- tmp := TIAByRange(RANGE_START, RANGE_FINISH);
- tmr[0][i] := (GetSystemTime - tm);
- SetLength(tmp, 0);
- Wait(10);
- tm := GetSystemTime;
- tmp := TIAByRange2bit(RANGE_START, RANGE_FINISH);
- SetLength(tmp, 0);
- tmr[1][i] := (GetSystemTime - tm);
- Wait(10);
- tm := GetSystemTime;
- tmp := TIAByRange4bit(RANGE_START, RANGE_FINISH);
- SetLength(tmp, 0);
- tmr[2][i] := (GetSystemTime - tm);
- Wait(10);
- tm := GetSystemTime;
- tmp := TIAByRange8bit(RANGE_START, RANGE_FINISH);
- tmr[3][i] := (GetSystemTime - tm);
- SetLength(tmp, 0);
- Wait(10);
- end;
- for i := 0 to 3 do
- begin
- WriteLn(TSA[i] + ' avg speed: ' + FloatToStr(TIAMean(tmr[i])) + ' ms.');
- SetLength(tmr[i], 0);
- end;
- SetLength(TSA, 0);
- end.
Advertisement
Add Comment
Please, Sign In to add comment