[Lazarus] How to program with time in milliseconds?

Tom Lisjac zikon770 at gmail.com
Sun May 18 01:49:02 CEST 2014


Dear Mr. Michael Van Canneyt,

I'm adding some clarification and context to your ongoing comments about
EpikTimer in this and other threads.

<< Snip EpikTimer code>>

>Why you would not use fpnanosleep on CPUX86_64 as well is a mystery to
me...

There's no mystery here. I wrote EpikTimer in 2003 with a few months of
experience on a 32 bit version of Lazarus. The code still works, but a lot
has changed around it over the last 11 years.

> Epiktimer is probably the most overrated component on lazarus-ccr. No
idea why people still recommend it, unless I missed something :(

No mystery here either. You never miss an opportunity to criticize
EpikTimer for reasons I've never been able to understand.

If there's another component or technique that does this better, can you
please recommend it rather then relentlessly criticizing the one I
contributed?

>> Of course in the end I need something that works for any CPU and OS.
> There is nothing. EpikTimer pretends to fill this gap, but it does not.
> Don't get me wrong: I have nothing against the epiktimer, but it is
presented as some super cross-platform solution (or so I perceive it).

To clarify, EpikTimer was created in 2003 to help simplify the measurement
of elapsed time. It used the x86 TSC hardware, if available and reverted to
the system clock if it wasn't. I needed this capability and thought others
might as well. My original version was documented to only work on 32 bit
Linux and was never presented as a "super cross-platform solution". Over
the years other contributors modified it for Windows and 64 bit operation.

Epiktimer was written during the early days of the Lazarus project when
cross platform capability was an evolving dream and the IDE was just
starting to be stable on Linux. The code is 11 years old, but despite it's
age, EpikTimer still works well, is downloaded many times per week and
actively used across a variety of projects. It could use an update and
re-release that I was starting to work on but at this point I've lost my
enthusiasm to complete it.

-Tom



On Mon, May 12, 2014 at 7:57 AM, Michael Van Canneyt <michael at freepascal.org
> wrote:

>
>
> On Mon, 12 May 2014, Reinier Olislagers wrote:
>
>  On 12/05/2014 13:32, Michael Schnell wrote:
>>
>>> On 05/11/2014 09:44 AM, Graeme Geldenhuys wrote:
>>>
>>>>
>>>> Take a look at EpikTimer. It uses hardware timers where available, with
>>>> an easy to use API for the developer.
>>>>
>>>
>>> IO took a look.
>>>
>>> Seemingly this is only available for X86 and X86_64.
>>>
>> How did you get that idea? The wiki page even explicitly mentions ARM.
>>
>
> Yes, it WORKS on arm.
>
> But on all systems except i386, you can just as well use Now() and
> Sleep(), because that is what epiktimer uses:
>
> (sources quoted from the lazarus-ccr repository)
>
> function SystemTicks: TickType;
> {$IFDEF Windows}
> begin
>   QueryPerformanceCounter(Result);
> {$ELSE}
> var t : timeval;
> begin
>   fpgettimeofday(@t,nil);
>   Result := (TickType(t.tv_sec) * 1000000) + t.tv_usec;
> {$ENDIF}
>
> and
>
> function TEpikTimer.SystemSleep(Milliseconds: Integer):Integer;
> {$IFDEF Windows}
> begin
>   Sleep(Milliseconds);
>   Result := 0;
> end;
> {$ELSE}
>   {$IFDEF CPUX86_64}
> begin
>   Sleep(Milliseconds);
>   Result := 0;
> end;
>   {$ELSE}
> var
>   timerequested, timeremaining: timespec;
> begin
>   timerequested.tv_sec:=Milliseconds div 1000;
>   timerequested.tv_nsec:=(Milliseconds mod 1000) * 1000000;
>   Result := fpnanosleep(@timerequested, @timeremaining) // returns 0 if ok
> end;
> {$ENDIF}
> {$ENDIF}
>
> Why you would not use fpnanosleep on CPUX86_64 as well is a mystery to
> me...
>
> Epiktimer is probably the most overrated component on lazarus-ccr. No idea
> why people still recommend it, unless I missed something :(
>
> Michael.
>
>
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20140517/2da39670/attachment-0003.html>


More information about the Lazarus mailing list