Merhaba;
Delphi de yazdığım program bir problemi çözüyor. Programın çalışma süresini CPU time olarak nasıl hesaplatabilriim?
Yardımcı olacak arkadaşlara şimdiden teşekkürler
cpu time hesaplama
Forum kuralları
Forum kurallarını okuyup, uyunuz!
Forum kurallarını okuyup, uyunuz!
kaynakOverview Beginning with the Pentium® processor, Intel processors allow the programmer to access a time-stamp counter. The time-stamp counter keeps an accurate count of every cycle that occurs on the processor. The Intel time-stamp counter is a 64-bit MSR (model specific register) that is incremented every clock cycle. On reset, the time-stamp counter is set to zero.
To access this counter, programmers can use the RDTSC (Read Time-Stamp Counter) instruction. This instruction loads the high-order 32 bits of the register into EDX, and the low-order 32 bits into EAX.
Time-stamp counter measures "cycles" and not "time". For example, two hundred million cycles on a 200 MHz processor is equivalent to one second of real time, while the same number of cycles on a 400 MHz processor is only one-half second of real time. Thus, comparing cycle counts only makes sense on processors of the same speed. To compare processors of different speeds, the cycle counts should be converted into time units, where:
# seconds = # cycles / frequency
Note: frequency is given in Hz, where: 1,000,000 Hz = 1 MHz
Why bother? The short answer is this: Fine Performance tuning. For a complete answer please refer to a following Intel document: Using the RDTSC Instruction for a Performance Monitoring. Zprofiler uses it internally to get extremely accurate timing results.
Delphi 2,3 (slow) Delphi 2 and 3 does not have a native Int64 data type support, the code below uses Comp data type which has 8 bytes in size but it is not a integer but floating-point type. Comp data type can be only return on ST(0) register (top of the floating-point stack). Because of that, code has to convert integer to float which is a relatively slow operation. Average overhead: 150 CPU cycles.
// D2, D3 - 150 cycles
function RDTSC: Comp; assembler;
asm
DB $0F,$31 // RDTSC opcode, result Int64 in EAX and EDX
PUSH EDX
PUSH EAX
FILD Comp([ESP])
ADD ESP, 8
end;
Delphi 2,3 (fast) I wrote code below to overcome conversion of integer to float. The trade off is this - it can't be a function but only a procedure. Average overhead: 88 CPU cycles, which is almost twice faster.
// D2, D3 - 88 cycles
procedure RDTSC(var Cycles: Comp); assembler;
asm
// EAX points to Cycles
MOV ECX,EAX // ECX points to Cycles
DB $0F,$31 // RDTSC opcode, result Int64 in EAX and EDX
MOV [ECX+4],EDX // Hi DWORD
MOV [ECX],EAX // Lo DWORD
end;
Delphi 4,5 Delphi 4 finally got a native Int64 data type support that is why code can be greatly simplified. It is a bit faster too. Average overhead: 84 CPU cycles.
// D4, D5 - 84 cycles
function RDTSC: Int64; assembler;
asm
DB $0F,$31 // RDTSC opcode, result Int64 in EAX and EDX
end;
Delphi 6,7 In Delphi 6 Borland completely rewrote inline assembler support, that is why code below can use an opcode name instead of emitting bytes. Average overhead: 84 CPU cycles.
// D6, D7 - 84 cycles
function RDTSC: Int64; assembler;
asm
RDTSC // result Int64 in EAX and EDX
end;
Notes: CPU cycles overhead calculated on 1400 MHz Pentium 4
http://www.geocities.com/izenkov/howto-rdtsc.htm
bi incele
delphi versiyonun yazmadığın için hepsini gonderdim
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
Forumun 365. Üyesi
Hiç Bir Şey İnsan Kadar Yükselemez ve Alçalamaz
Erkan ÇAĞLAR
Forumun 365. Üyesi
Hiç Bir Şey İnsan Kadar Yükselemez ve Alçalamaz
Erkan ÇAĞLAR
- uğur alkan
- Üye
- Mesajlar: 227
- Kayıt: 29 Ağu 2004 04:49
- Konum: Istanbul
bunuda bi incele komponent olarak ben kullanıyorum oldukça başarılı
http://www.torry.net/quicksearchd.php?S ... &Title=Yes
HighResTimer v.1.02
http://www.torry.net/quicksearchd.php?S ... &Title=Yes
HighResTimer v.1.02
Bazen sert rüzgarlar eser başını öne eğmekten asla korkma
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
Forumun 365. Üyesi
Hiç Bir Şey İnsan Kadar Yükselemez ve Alçalamaz
Erkan ÇAĞLAR
Forumun 365. Üyesi
Hiç Bir Şey İnsan Kadar Yükselemez ve Alçalamaz
Erkan ÇAĞLAR