線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1909
推到 Plurk!
推到 Facebook!

Timer 元件無法測回圈執行時間?

尚未結案
eulor2000
一般會員


發表:51
回覆:34
積分:17
註冊:2008-11-18

發送簡訊給我
#1 引用回覆 回覆 發表時間:2010-01-22 01:47:51 IP:218.175.xxx.xxx 訂閱
   如題我想用Timer元件去測執行時間,發現竟然不行請指導依下

CODE
#include
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
long counter_f;
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
counter_f=0;
Timer1->Enabled=true;
for(int j=0;j<=400;j )
{
for(int i=0;i<=400;i )
{
Canvas->Pixels [i][j]=clBlue;
}
}
Timer1->Enabled=false;
Label1->Caption="Time:" IntToStr(counter_f) "ms";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Refresh();
Label1->Caption="Time:" IntToStr(0) "ms";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
counter_f ;
}
//---------------------------------------------------------------------------

eulor2000
一般會員


發表:51
回覆:34
積分:17
註冊:2008-11-18

發送簡訊給我
#2 引用回覆 回覆 發表時間:2010-01-22 09:00:46 IP:218.175.xxx.xxx 訂閱
在參考http://delphi.ktop.com.tw/board.php?cid=168&fid=912&tid=72272&action=AddMyGood
已解決......感謝這幾篇版友...^^
GrandRURU
站務副站長


發表:240
回覆:1680
積分:1874
註冊:2005-06-21

發送簡訊給我
#3 引用回覆 回覆 發表時間:2010-01-22 09:07:31 IP:203.75.xxx.xxx 未訂閱
一定要用Timer嗎?

換個方式如何呢?
[code cpp]
int starttime=clock();
int stoptime,timeused;

for(...)
{
.....
}

stoptime=clock();
timeused=stoptime-starttime;
[/code]

===================引 用 eulor2000 文 章===================
如題我想用Timer元件去測執行時間,發現竟然不行請指導依下
CODE
#include
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"

long counter_f;
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
counter_f=0;
Timer1->Enabled=true;
for(int j=0;j<=400;j )
{
for(int i=0;i<=400;i )
{
Canvas->Pixels [i][j]=clBlue;
}
}
Timer1->Enabled=false;
Label1->Caption="Time:" IntToStr(counter_f) "ms";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Refresh();
Label1->Caption="Time:" IntToStr(0) "ms";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
counter_f ;
}
//---------------------------------------------------------------------------

acmaeiou
一般會員


發表:4
回覆:9
積分:2
註冊:2010-06-18

發送簡訊給我
#4 引用回覆 回覆 發表時間:2010-09-20 14:43:39 IP:114.32.xxx.xxx 未訂閱
感謝GrandRURU大的範例程式碼,小弟最近剛好也要測執行時間
系統時間:2024-03-28 21:36:24
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!