News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Getting system time

Started by Norad00, April 06, 2005, 05:06:10 PM

Previous topic - Next topic

Norad00

Anyone know how to retrieve the system date and time?

Norad00

Just thought I would provide some info as to what I am trying to do.

I am trying to record the start and end time of my program for speed testing.

Program should work like this

Record Start Time
Do Stuff
Record End Time
Show How long it took to Do Stuff

Thanks for any help!!

P1

Welcome Norad00      :U     

Glad to have you here!     :dance:

You will find some the best people in the world, come here to get answers, as well as give them.

If you like getting and giving help in Assembler, this is the place for you!!    :clap:     

Look forward to you participating with us.      :thumbu   

LOCAL LocalTime:SYSTEMTIME

invoke GetLocalTime, ADDR LocalTime


Look up the structure of SYSTEMTIME to find the different parts you are interested in.

Regards,  P1  :8)

MichaelW

Norad00,

Unless your stuff takes a long time to do, or you need very precise timing, you should probably use GetTickCount

eschew obfuscation

thomasantony

Hi,
You can also use the GetSystemTime API. BTW The GetTickCount counts the number of ticks since booting up of the system only AFAIK. I think RDTSC aslo does the same thing but with better precision. (Returns QWORD unlike DWORD in GetTickCount)

Thomas
There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free

liquidsilver

I'd say that GetLocalTime is for if you need the actual time, use RDTSC if you need the difference for comparison of optimization. Check out the post on timing at http://www.masmforum.com/simple/index.php?topic=770.0 for better timing.

Norad00

Thanks for the info everyone. GetLocalTime seems to work well for my purpose.

BoR0

Here is how I do it. I think its the fastest possible way using APIs. GetSystem/LocalTime is slower than GetTickCount

Anyway, here's the code:

.data
buffer db 16 dup(0)
prefix db "%d ms", 0

.code
CheckTimeStamp PROC lpAddress:DWORD
call GetTickCount
push eax

call lpAddress

pop eax
mov ecx, eax
call GetTickCount
sub eax, ecx
ret
CheckTimeStamp ENDP

blahcode PROC
xor ecx, ecx
@@:
nop

inc ecx
cmp ecx, 0FFFFFFFFh
jne @B
sub eax, ecx
ret
blahcode ENDP

start:
invoke CheckTimeStamp, ADDR blahcode
invoke wsprintf, ADDR buffer, ADDR prefix, eax
invoke MessageBox,0,ADDR buffer,0,0
invoke ExitProcess,0
end start


It is how I am measuring how many seconds will calling NOP for 0FFFFFFFFh times take.
Please note that this is not accurate but it is somewhere near to the right results.
Takes around 6 seconds on my 1.6GHz  :bg

Good Luck!  :U

thomasantony

Hi Bor0,
      I think he wanted to get the current time and not timing. Anyway you proc will prove very useful. I still don't know how you can load a QWORD in edx:eax into the FPU register., which is returned by the RDTSC instruction

Thomas :U
There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free

Synfire

; Get Time
;  Example Results:  tbuf contains the string "12:16 PM"
invoke   GetLocalTime,addr tmnd
invoke   GetTimeFormat,NULL,NULL,addr tmnd,SADD("hh':'mm tt"),addr tbuf,sizeof tbuf

; Get Date
; Example Results: tbuf contains the string "04/08/2005"
invoke   GetLocalTime,addr tmnd
invoke   GetDateFormat,NULL,NULL,addr tmnd,SADD("MM'/'dd'/'yyyy"),addr tbuf,sizeof tbuf

Hope this helps.

Regards,
Bryant Keller

BoR0

Well, I am assuming he wanted timing, since he said this:

QuoteRecord Start Time
Do Stuff
Record End Time
Show How long it took to Do Stuff

However, I might be wrong :bdg

Good Luck! :U

thomasantony

Ohhhh,
   I hadn't seen that. YOu get oversight with age you know :wink . I turned 16 a fortnight ago.
:lol

Thomas :P :bdg :lol :cheekygreen: :green2 :U
There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free

BoR0

Happy birthday! :lol

I am almost 17 myself too  :U

Phoenix

Norad00,

perhaps these codesnippets are of interest for you:


.DATA?

lpFreq        LARGE_INTEGER <?>
lpPCount_1    LARGE_INTEGER <?>
lpPCount_2    LARGE_INTEGER <?>
udwMs         DWORD ?

.CODE
;
;
.ELSEIF uMsg == WM_CREATE
;-- We need to retrieve the frequency of the performance counter frequency once:
    invoke QueryPerformanceFrequency,Offset lpFreq

;Somewhere in code:
    Invoke BeginTiming

;-- Do something....

    Invoke EndTiming
    mov udwMs,eax
;   Invoke dwtoa,eax,ADDR szBuf
;   Invoke SetWindowText,hWnd,ADDR szBuf

;--------------------------------------------------------

;-- Timing Procs:

BeginTiming Proc
    Invoke QueryPerformanceCounter,Offset lpPCount_1
    RET
BeginTiming EndP


EndTiming Proc

    Invoke QueryPerformanceCounter,Offset lpPCount_2
    push 1000
    finit
    fild QWORD PTR lpPCount_2.QuadPart  ; END: performance-counter value
    fild QWORD PTR lpPCount_1.QuadPart  ; START: performance-counter value
    fsubp st(1),st                      ; st(0)=END-START
    fild QWORD PTR lpFreq.QuadPart      ; st(0)=lpFreq,st(1)=END-START
    fdivp st(1),st                      ; st(0)=(END-START)/lpFreq
    fild DWORD PTR [esp]                ; st(0)=1000
    fmulp st(1),st                      ; st(0)=(END-START)/lpFreq*1000
    fistp DWORD PTR [esp]               ; store milliseconds as integer
    pop eax                             ; load ms to eax and cleanup fpu stack

    RET
EndTiming EndP


Regards, phoenix