delphi 计算函数执行时间 TStopwatch
发布时间:2020-12-15 09:55:42 所属栏目:大数据 来源:网络整理
导读:先定义两个函数 function sumX(x,y: Integer): Integer; function sumY(x,y: Integer): Integer; inline ; 计算函数执行时间 procedure TForm5.Button5Click(Sender: TObject); var sw: TStopwatch; i,j: Integer; begin j : = 0 ; sw : = TStopwatch.StartN
先定义两个函数 function sumX(x,y: Integer): Integer; function sumY(x,y: Integer): Integer; inline; 计算函数执行时间 procedure TForm5.Button5Click(Sender: TObject); var sw: TStopwatch; i,j: Integer; begin j := 0; sw := TStopwatch.StartNew; for i := 0 to 100000000 do begin j := sumX(i,j); //普通函数 end; sw.Stop; ShowMessage(‘first do expand time =‘ + IntToStr(sw.ElapsedMilliseconds) + ‘ ‘); //602 j := 0; sw := TStopwatch.StartNew; for i := 0 to 100000000 do begin j := sumY(i,j); //inline函数 end; sw.Stop; ShowMessage(‘second do expand time =‘ + IntToStr(sw.ElapsedMilliseconds) + ‘ ‘); //595 end; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |