Sign in Join
Wiki copytemporary

EpikTimer: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11### About
22
33EpikTimer is a programmer's stopwatch that is capable of measuring very short events with traceably high precision over long periods of time. It's simple to use, consumes virtually no CPU and requires only 25 bytes of ram to implement a timer instance. The component provides a single internal timer... but unlimited numbers can be declared externally and linked to a single EpikTimer component on the form.
44
55The download contains the component, an installation package and a demo application, that illustrates the features of the component along with some instrumentation for evaluating the clock sources on a given system.
66
77This component was designed for cross-platform applications and was written specifically for the Lazarus IDE and Free Pascal Compiler and includes a demo application.
88
99### Author
1010
1111Tom Lisjac
1212
1313### License
1414
1515[LGPL](http://www.opensource.org/licenses/lgpl-license.php) (please contact the author if the LGPL doesn't work with your project licensing)
1616
1717### Download
1818
1919The **source code** can be downloaded from the Git repository as follows:
2020
21-` git clone `[`https://github.com/graemeg/epiktimer.git`](https://github.com/graemeg/epiktimer.git)
21+```text
22+ git clone https://github.com/graemeg/epiktimer.git
23+```
2224
2325If you don't want to install a Git client, Github also allows you to download the latest code as a ZIP archive. Simply go to the [Github EpikTimer](https://github.com/graemeg/epiktimer) url and click the "Download ZIP" button on the right.
2426
2527All **tagged releases** can be downloaded in .zip or .tar.gz format by going to this [Github Releases](https://github.com/graemeg/epiktimer/releases) url and select the zip or tar.gz link for whichever release you want to download.
2628
2729### Project Status
2830
2931- Production/Stable
3032
3133### Change Log
3234
3335- Initially written on 24-06-2003 TL
3436- Pre-release 30-06-2003 TL - Needs testing on the BSD's and Win32
3537- Version 0.1 1-7-2003 TL
3638
37391. initial beta release
3840
3941- Version 0.2 3-7-2003 TL
4042
41431. Revised logic around hardware detection to prevent executing extended instructions if the HasCapabilityData call returns false.
42442. Removed exposed low level diagnositic functions from unit interface.
43453. Revised demo.
4446
4547- Version 0.3 15-11-2005
4648
47491. Updated 0.2 version to make it compile on the latest Lazarus (0.9.10).
48502. Added LCL to the required packages.
49513. Changed mode to Delphi in order to compile.
50524. Changed windows timebase to use QueryPerformanceCounter, because has a much greater precision then GetSystemTime.
51535. Added changes to ensure the component compiles on Delphi 7.0
52546. Made tests on Windows and Linux
53557. Small changes to the demo to make it compile
5456
5557- Version 1.0 06-10-2006
5658
57591. Changes for 64 bits operation
58602. Added units BaseUnix, Unix and UnixUtil, removed oldlinux (obsolete)
59613. Gettimeofday -\> fpGettimeofday
60624. Changed systemsleep for 64 bits systems
61635. Some changes in timeval
62646. Tested on AMD64 (linux)
6365
6466For any later changes, please see the Git commit log.
6567
6668### Dependencies / System Requirements
6769
6870- Nanosecond resolution is supported on Intel Pentium versions with a Timestamp Counter.
6971- Microsecond system clock is the default timebase.
7072
7173Tested on:
7274
7375- Pentium IV 3,2Ghz on Windows and Linux with great precision (~ 3,220,000,000 ticks per second)
7476- Pentium 233Mhz with Damn Small Linux. Works great with hardware clock.
7577- Mobile AMD 64 Athlon 3200+ on Windows XP Home (32 bit), Lazarus 9.13
7678- AMD 64 CPU, running 64 bit version of Ubuntu Linux, Lazarus 9.18.
7779- Intel i7-3770K, running 64-bit version of FreeBSD 9.1, using FPC 2.6.2
7880- ARM CPU using Raspberry Pi and FPC 2.6.2
7981
8082### Installation in Lazarus IDE
8183
8284- In Components/Open Package File, open etpackage.lpk
8385- Compile the package and close the package dialog
8486- In Components -\> Open Package File, open the etpackage_dsgn.lpk
8587- Compile the package.
8688- Click the Install button and let Lazarus rebuild
8789- Component will be in the System Palette (stopwatch-ruler icon)
8890
8991### Usage
9092
9193Drop the component on a form. The component contains a single timer instance and parameterless calls to start, stop, elapsed and clear will implicitly reference it.
9294
9395**If the timer is named ET**
9496
9597``` pascal
9698uses epiktimer;
9799
98100var
99101 ET: TEpikTimer;
100102
101103procedure InitTimer;
102104begin
103105 ET := TEpikTimer.Create(Application);
104106end;
105107
106108procedure InstrumentedCall;
107109Begin
108110 ET.Clear; // optional... timer is cleared at creation
109111 ET.Start;
110112 ExecuteFirstTimedSection;
111113 ET.Stop; // the timer is actually paused and can be restarted later
112114 TimedSection1:=ET.Elapsed; // store the elapsed in a global
113115 MakeAnUntimedOverheadCall; // not counted in the timer
114116 ET.Start; //resume the timer... continue accumulating ticks
115117 CallTimedSection2;
116118 TimedSection2:=ET.Elapsed; //timer keeps running... we've just sample it.
117119 CallTimedSection3;
118120 CallSomethingElse;
119121 TimedSection3:=ET.Elapsed; //keep counting... tap the elapsed
120122 CallTimedSection4;
121123 TimedSection4:=ET.Elapsed; //keep counting... tap the elapsed
122124 ET.clear // done... timer is stopped and zeroed
123125end;
124126```
125127
126128You can also create any number of timers from a single component on the form by declaring a TimerData record and passing it as a parameter to start, stop, elapsed and clear using the overloaded methods in the component. An example would be:
127129
128130``` pascal
129131Function TimedExecution: Extended;
130132Var
131133 DiskAccessTime:TimerData;
132134Begin
133135 ET.Clear(DiskAccessTimer); // Declared timers *must* be cleared before use.
134136 ET.Start(DiskAccessTimer);
135137 ExecuteTheTimedSection;
136138 Result:=ET.Elapsed(DiskAccessTimer); // the timer keeps running...
137139 etc...
138140```
139141
140142One particular use for EpikTimer is checking if a given amount of time has elapsed before continuing with a task or to another iteration of the same task.
141143
142144``` pascal
143145DelayInSeconds := 8.5; // or any value
144146OldTime := ET.Elapsed;
145147
146148while ((ET.Elapsed - OldTime) < DelayInSeconds) do
147149begin
148150 ET.SystemSleep(10);
149151end;
150152
151153// DelayInSeconds has elapsed and now you can continue executing the code
152154```
153155
154156See etdemo.pas for additional examples of component usage
155157
156158#### EpikTimer as a profiler
157159
158160EpikTimer can be used to profile the speed of procedures:
159161
160162``` pascal
161163uses
162164 {$ifdef PROFILING}epiktimer,{$endif}
163165 ...
164166
165167type
166168 TMyClass = class
167169 private
168170 {$ifdef PROFILING}
169171 profiler: Tepiktimer;
170172 {$endif}
171173 ...
172174 end;
173175
174176implementation
175177
176178constructor TMyClass.Create(AOwner: TComponent);
177179begin
178180 inherited Create(AOwner);
179181
180182 ...
181183
182184 {$ifdef CARDROOM_PROFILING}
183185 profiler := TEpikTimer.Create(Self)
184186 {$endif}
185187end;
186188
187189procedure TMyClass.MethodToBeProfiled;
188190begin
189191 {$ifdef PROFILING}
190192 profiler.Clear;
191193 profiler.Start;
192194 {$endif}
193195 // do stuff
194196 {$ifdef PROFILING}
195197 OPDebugLn('TMyClass.MethodToBeProfiled ' + FloatToStr(profiler.Elapsed));
196198 {$endif}
197199end;
198200```
199201
200202### The ETDemo Application
201203
202204The ETDemo application does not require EpikTimer to be installed in order to compile and operate. I never liked having to install a palette full of components only to find out that I didn't like any of them! :)
203205
204206**Installation**
205207
206208- Open etdemo.lpi
207209- compile
208210- run
209211
210212### Console application
211213
212214If you don't have an "Application" object instance as above, simply create the EpikTimer instance as follows. It must be manually freed when you are all done with it:
213215
214-` ET := TEpikTimer.Create(nil)`\
215-` ... your code here ...`\
216-` ET.Free;`
216+``` pascal
217+ ET := TEpikTimer.Create(nil)
218+ ... your code here ...
219+ ET.Free;
220+```
217221
218222### See also
219223
220224- [[doc:fcl/fptimer/index.html|FPTimer included with FPC/Lazarus]]
221225- [[Yet another Running Timer]]
222226
223227---
224228*From the Free Pascal wiki, page "EpikTimer", as it stood on 2019-08-09 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
225229Category: Components

Back to history