Jump to content

what does Timerinit() timestamp represent?


Recommended Posts

That's exactly what I'm trying to say. I've been told it returns ticks and I've been told that ticks = milliseconds I don't know what the heck ticks are, or even if the timestamp is in ticks. What I really want to know is how to turn the timestamps into milliseconds or seconds even. I want to be able to manipulate the timestamps do math on them and all that, but to do that I need them in some variant of seconds (seconds or milliseconds)

I'm thinking of totally giving up on timerinit() and useing _datediff('s', x, y)

The help file is pretty useless in this case, it says it returns a timestamp in milliseconds which it does not. There is 2 things that I want to do:

1) be able figure out the ammount of time between 2 timestamps

2) be able to add or subtract time from a timestamp

So i take a timestamp and if 10 mins passes then i do something But if I pause the script using my custom tray pause another timer is started and when its unpaused i run timerdiff() to see how long it was paused for then I want to add that time to the original timestamp so that the time its paused for doesn't count towards the 10 mins There are some other things I want to do but this is the biggest problem I'm running into. Since I don't know the units of the timestamp, I can't manipulate it. I thought it was in milliseconds, but it didn't work as it was supposed to.

I don't understand your problem perhaps because although I agree that TimerINit() doesn't return mS, I don't see it's a problem because you only need to use TimerDiff.

If you want to measure time since event A then at event A you say

$EventA - TimerInit()

Then the time since event is is always TimerDiff($EventA)

If there is a second and third event then

$eventB = TimerInit()

$EventC = TimerInit()

Then, if you want to know the time that has elapsed since A, but discount the time between B and C you say

$TimefromAlessBtoC = Timerdiff($EventA) -(TimerDiff($eventB) - TimerDif($eventC))

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • Moderators

Yes and that is what the OP has been saying all the time as as I have understood it.

@Smoke_N

The point is that if TimerInit() returns a time related to mS since the last boot then the difference between the returns from two TimerInit() calls should be equal to the time between the calls in mS. It isn't. So when the Help says that TimerInit() returns a timestamp in mS what does it mean by a time stamp? On two PC's I've tried I get about 3500 times the number of mS (approx).

I guess I am just not following the thread.

In other languages, I use QueryPerformanceCounter and QueryPerformanceFrequency. I probably got that idea from AutoIt lol... having said that... not quite sure where everyone is getting that TimerInit() uses time since last reboot (aka: GetTickCount ).

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I guess I am just not following the thread.

In other languages, I use QueryPerformanceCounter and QueryPerformanceFrequency. I probably got that idea from AutoIt lol... having said that... not quite sure where everyone is getting that TimerInit() uses time since last reboot (aka: GetTickCount ).

Well there is this old thread here:

http://www.autoitscript.com/forum/index.ph...imerinit++ticks

Link to comment
Share on other sites

  • Moderators

And then there's old source:
///////////////////////////////////////////////////////////////////////////////
// TimerInit()
// Returns a floating point value that is a baseline system time.
// Starts tracking a high performance counter allowing for accurate timers.
///////////////////////////////////////////////////////////////////////////////

AUT_RESULT AutoIt_Script::F_TimerInit(VectorVariant &vParams, Variant &vResult)
{
    __int64 now;

    if (!QueryPerformanceCounter((LARGE_INTEGER *)&now))
        return AUT_OK;

    vResult = (double)now;

    return AUT_OK;

} // TimerInit()
:)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Eureka?!?!

These should both output your system uptime...once again verified with Everest Ultimate.

TimerConvert(TimerInit()/2394049.99993096)
TimerConvert(TimerDiff(0))

Func TimerConvert($timestamp)
    $milliseconds = $timestamp
    $years = Int($milliseconds / 31536000000)
    $remainMS = Mod($milliseconds, 31536000000)
    $days = Int($remainMS / 86400000)
    $remainMS = Mod($milliseconds, 86400000)
    $hours = Int($remainMS / 3600000)
    $remainMS = Mod($milliseconds, 3600000)
    $minutes = Int($remainMS / 60000)
    $remainMS = Mod($milliseconds, 60000)
    $seconds = Int($remainMS / 1000)
    $remainMS = Mod($milliseconds, 1000)

    $format = StringFormat("%s years, %s days, %s h, %s m, %s s, %s ms",$years,$days,$hours,$minutes,$seconds,Int($remainMS))
    ConsoleWrite($format & @CRLF)
EndFunc
Link to comment
Share on other sites

What is «2394049.99993096»? :)

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

What is «2394049.99993096»? :)

I don't know how I figured it out but...

$tick = TimerInit()/TimerDiff(0) ;$tick = 2394049.99993096

;Convert milliseconds to Years,Days,Hours,Minutes,Seconds,Milliseconds
TimerConvert(TimerInit()/$tick) ;Uptime
TimerConvert(TimerDiff(0)) ;Uptime

Func TimerConvert($timestamp)
    $milliseconds = $timestamp
    $years = Int($milliseconds / 31536000000)
    $remainMS = Mod($milliseconds, 31536000000)
    $days = Int($remainMS / 86400000)
    $remainMS = Mod($milliseconds, 86400000)
    $hours = Int($remainMS / 3600000)
    $remainMS = Mod($milliseconds, 3600000)
    $minutes = Int($remainMS / 60000)
    $remainMS = Mod($milliseconds, 60000)
    $seconds = Int($remainMS / 1000)
    $remainMS = Mod($milliseconds, 1000)

    $format = StringFormat("%s years, %s days, %s h, %s m, %s s, %s ms",$years,$days,$hours,$minutes,$seconds,Int($remainMS))
    ConsoleWrite($format & @CRLF)
EndFunc
Edited by weaponx
Link to comment
Share on other sites

I don't know how I figured it out but...

$tick = TimerInit()/TimerDiff(0) ;$tick = 2394049.99993096

I get a slightly diff value when I run that, so it must be system specific. Is there any way I can find the code for the timerdiff function and see how it figures it out? What file do I look in to find the code for that?

Link to comment
Share on other sites

I get a slightly diff value when I run that, so it must be system specific. Is there any way I can find the code for the timerdiff function and see how it figures it out? What file do I look in to find the code for that?

Smoke posted it like 4 posts ago.

Edited by weaponx
Link to comment
Share on other sites

  • Moderators

I get a slightly diff value when I run that, so it must be system specific. Is there any way I can find the code for the timerdiff function and see how it figures it out? What file do I look in to find the code for that?

Like a dog chasing your tail here.

///////////////////////////////////////////////////////////////////////////////
// TimerDiff(Baseline)
// Takes the time difference between now and Baseline and returns the result.
///////////////////////////////////////////////////////////////////////////////

AUT_RESULT AutoIt_Script::F_TimerDiff(VectorVariant &vParams, Variant &vResult)
{
    __int64 freq, now;

    if (!QueryPerformanceFrequency((LARGE_INTEGER *)&freq))
        return AUT_OK;

    if (!QueryPerformanceCounter((LARGE_INTEGER *)&now))
        return AUT_OK;

    vResult = (((double)now - vParams[0].fValue()) / (double)freq) * 1000.0;

    return AUT_OK;

} // TimerDiff()

Not a fan of magic code, the example I posted before in post 5 should have sufficed (if not at least the dll call) for what you are attempting.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Smoke posted it like 4 posts ago.

Smoke posted timerinit() I'm looking for timerdiff() to see how it changes from ticks to milliseconds or whatever it does.

Edit: Nevermind, I didn't see the next page as i was responding to this

Edited by Mixam
Link to comment
Share on other sites

  • Moderators

Might be able to utilize this one timeGetTime to suit your needs.

Dim $nTimeStart = _TimerStart()
While 1
    ConsoleWrite(_TimerCheck($nTimeStart) & @CRLF)
    Sleep(100)
WEnd

Func _TimerStart()
    Local $atGT = DllCall("Winmm.dll", "dword", "timeGetTime")
    If IsArray($atGT) Then Return $atGT[0]
    Return 0
EndFunc

Func _TimerCheck($nTime)
    Return _TimerStart() - $nTime
EndFunc

Edit:

Removed unused variable.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I don't understand your problem perhaps because although I agree that TimerINit() doesn't return mS, I don't see it's a problem because you only need to use TimerDiff.

If you want to measure time since event A then at event A you say

$EventA - TimerInit()

Then the time since event is is always TimerDiff($EventA)

If there is a second and third event then

$eventB = TimerInit()

$EventC = TimerInit()

Then, if you want to know the time that has elapsed since A, but discount the time between B and C you say

$TimefromAlessBtoC = Timerdiff($EventA) -(TimerDiff($eventB) - TimerDif($eventC))

Martin: Sorry i didn't reply to you sooner, I was off on another tangent. I can't do it that way when people pause/unpause multiple times.

Smoke: I reread the 5th post and at the time i had discounted it because I saw it returned in days, months, years etc and I was looking for seconds or milliseconds, upon rereading I see that I just have to remove some of your code and I will have it in milliseconds. I'll have to look more into it, but it might work for my purposes. Also I saw your latest reply and I will have to look at it later when I get time and see if that is another option for me. The reason I've been attempting to figure out how to convert timerinit into milliseconds is because i already wrote the code thinking it was in milliseconds. So it would be easy for me to just take that timestamp and say divide it by TimerInit()/TimerDiff(0) or something. Anways I gotta go so I'll look into your latest post when I get back.

Edit: by the way I'll also have to be able to take a date from in a file such as "Mar 03 2008 10:23:45" and be able to convert it into whatever timestamp I end up using. I've already managed to do that with datediff since epoch so I know its doable at least. Anyways really gotta go now. Thanks for all the help.

Edited by Mixam
Link to comment
Share on other sites

  • Moderators

That only covered 95 through XP it seems, this seems to be more to the point, but I did notice it's off about 6 or 7 ms on my machine due to the time to pass from function to function.

Dim $nTimeStart = _TimerStart()
While 1
    ConsoleWrite(_TimerCheck($nTimeStart) & @CRLF)
    Sleep(100)
WEnd

Func _TimerStart()
    Local $atGT
    If @OSTYPE = "WIN32_WINDOWS" Then
        $atGT = DllCall("Winmm.dll", "dword", "timeGetTime")
    Else
        $atGT = DllCall("Kernel32.dll", "dword", "GetTickCount")
    EndIf
    If IsArray($atGT) Then Return $atGT[0]
    Return 0
EndFunc

Func _TimerCheck($nTime)
    Local $nCurrent = _TimerStart()
    Return $nCurrent - $nTime
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

That only covered 95 through XP it seems, this seems to be more to the point, but I did notice it's off about 6 or 7 ms on my machine due to the time to pass from function to function.

Dim $nTimeStart = _TimerStart()
While 1
    ConsoleWrite(_TimerCheck($nTimeStart) & @CRLF)
    Sleep(100)
WEnd

Func _TimerStart()
    Local $atGT
    If @OSTYPE = "WIN32_WINDOWS" Then
        $atGT = DllCall("Winmm.dll", "dword", "timeGetTime")
    Else
        $atGT = DllCall("Kernel32.dll", "dword", "GetTickCount")
    EndIf
    If IsArray($atGT) Then Return $atGT[0]
    Return 0
EndFunc

Func _TimerCheck($nTime)
    Local $nCurrent = _TimerStart()
    Return $nCurrent - $nTime
EndFunc
Thanks for all the help, I think I got all the stuff i need to scrap timerinit and try using a diff method now. Thanks for all the options to look at.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...