gettingstarted
[Top] [All Lists]

Re: timer accuracy

To: Getting Started <gettingstarted at lists dot realsoftware dot com>
Subject: Re: timer accuracy
From: Phil Heycock <pheycock at bellsouth dot net>
Date: Sat, 31 Jan 2004 12:41:08 -0500
Additionally, all calls have some time overhead associated with them. Try
this, maybe in a PB action event:

Sub Action()

    Dim start, finish, deltaT, overhead as Double
    Dim i as integer

    start = Microseconds

    #Pragma BackgroundTasks False
    // some arbitrary number of iterations
    // (10, 100, 1000, 10000) (experiment)

    For i = 1 to 1000
       finish = microseconds
    Next

    #Pragma BackgroundTasks True

    deltaT = finish - start
    overhead = deltaT/1000
    EditField1.text = str(overhead)

End Sub

Depending on how tight your timing requirements are, you might have to take
this overhead into account. On my machine (G4-400), overhead for
microseconds call is around 2 microseconds. As an example: if I am looking
for benchmarking results in the range of 20 to 40 microseconds, 2
microseconds represents 5% - to - 10% of scale, which is significant, and
should be taken into account. If I am looking for results in the range of
2000 to 4000 microseconds (for example), call overhead is not that
significant, and might be disregarded.

If I have an application which involves benchmarking, I typically have a
GLOBAL variable 'tOverhead', which is established during program
initialization by a method similar to that shown above. Then, benchmark
calculations become:

    start = microseconds
    // do something
    finish = microseconds
    // find out how long it took to 'do something'
    deltaT = finish - start - tOverhead

PWH
*****************************************************
on 1/31/04 11:58 AM, Lars Jensen at larsjensen at rcn dot com wrote:

>> Are timers synchronized to the system clock?  If so, when?  If not,
>> are they really that accurate?
> 
> No, and no. As I understand them, timers are very simple -- when RB does
> background processing, it says to each timer: "if the current time is
> greater than the last time you fired off plus your period, then fire off
> again".
> 
> That's it, no synchronization, no accuracy guarantees (other than that a
> timer will never go off _faster_ than its period, but it can take very much
> longer).
> 
> lj


 - - -
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>