?? cprofile.bk2
字號(hào):
{-----------------------------------------------------------------------------
Unit Name: CProfile
Author: hubdog(陳省)
Email: hubdog@263.net
Purpose: 演示如何使用GpProfile來(lái)分析程序運(yùn)行的性能
History:
2003-4-4 創(chuàng)建本單元
-----------------------------------------------------------------------------}
unit CProfile;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure BubbleSort(var A: array of Integer);
procedure SelectionSort(var A: array of Integer);
procedure QuickSort(var A: array of Integer);
procedure RandomizeArrays;
end;
type
TSortArray = array[0..30000] of Integer;
var
Form1: TForm1;
BubbleSortArray, SelectionSortArray, QuickSortArray: TSortArray;
implementation
{$R *.dfm}
//起泡排序
procedure TForm1.BubbleSort(var A: array of Integer);
var
I, J, T: Integer;
begin
for I := High(A) downto Low(A) do
for J := Low(A) to High(A) - 1 do
if A[J] > A[J + 1] then
begin
T := A[J];
A[J] := A[J + 1];
A[J + 1] := T;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
//初始化數(shù)組
RandomizeArrays;
//執(zhí)行三個(gè)排序
BubbleSort(BubbleSortArray);
SelectionSort(SelectionSortArray);
QuickSort(QuickSortArray);
end;
//快速排序
procedure TForm1.QuickSort(var A: array of Integer);
procedure QuickSort(var A: array of Integer; iLo, iHi: Integer);
var
Lo, Hi, Mid, T: Integer;
begin
Lo := iLo;
Hi := iHi;
Mid := A[(Lo + Hi) div 2];
repeat
while A[Lo] < Mid do
Inc(Lo);
while A[Hi] > Mid do
Dec(Hi);
if Lo <= Hi then
begin
T := A[Lo];
A[Lo] := A[Hi];
A[Hi] := T;
Inc(Lo);
Dec(Hi);
end;
until Lo > Hi;
if Hi > iLo then QuickSort(A, iLo, Hi);
if Lo < iHi then QuickSort(A, Lo, iHi);
end;
begin
QuickSort(A, Low(A), High(A));
end;
//初始化用于排序的數(shù)組
procedure TForm1.RandomizeArrays;
var
I: Integer;
begin
Randomize;
for I := Low(BubbleSortArray) to High(BubbleSortArray) do
BubbleSortArray[I] := Random(170);
SelectionSortArray := BubbleSortArray;
QuickSortArray := BubbleSortArray;
end;
procedure TForm1.SelectionSort(var A: array of Integer);
var
I, J, T: Integer;
begin
for I := Low(A) to High(A) - 1 do
for J := High(A) downto I + 1 do
if A[I] > A[J] then
begin
T := A[I];
A[I] := A[J];
A[J] := T;
end;
end;
end.
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -