Sign in Join
Wiki copytemporary

EpikTimer: what changed

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

Title: EpikTimer

OldNewLine
1+### About
2+
3+EpikTimer 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.
4+
5+The 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.
6+
7+This component was designed for cross-platform applications and was written specifically for the Lazarus IDE and Free Pascal Compiler and includes a demo application.
8+
9+### Author
10+
11+Tom Lisjac
12+
13+### License
14+
15+[LGPL](http://www.opensource.org/licenses/lgpl-license.php) (please contact the author if the LGPL doesn't work with your project licensing)
16+
17+### Download
18+
19+The **source code** can be downloaded from the Git repository as follows:
20+
21+` git clone `[`https://github.com/graemeg/epiktimer.git`](https://github.com/graemeg/epiktimer.git)
22+
23+If 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.
24+
25+All **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.
26+
27+### Project Status
28+
29+- Production/Stable
30+
31+### Change Log
32+
33+- Initially written on 24-06-2003 TL
34+- Pre-release 30-06-2003 TL - Needs testing on the BSD's and Win32
35+- Version 0.1 1-7-2003 TL
36+
37+1. initial beta release
38+
39+- Version 0.2 3-7-2003 TL
40+
41+1. Revised logic around hardware detection to prevent executing extended instructions if the HasCapabilityData call returns false.
42+2. Removed exposed low level diagnositic functions from unit interface.
43+3. Revised demo.
44+
45+- Version 0.3 15-11-2005
46+
47+1. Updated 0.2 version to make it compile on the latest Lazarus (0.9.10).
48+2. Added LCL to the required packages.
49+3. Changed mode to Delphi in order to compile.
50+4. Changed windows timebase to use QueryPerformanceCounter, because has a much greater precision then GetSystemTime.
51+5. Added changes to ensure the component compiles on Delphi 7.0
52+6. Made tests on Windows and Linux
53+7. Small changes to the demo to make it compile
54+
55+- Version 1.0 06-10-2006
56+
57+1. Changes for 64 bits operation
58+2. Added units BaseUnix, Unix and UnixUtil, removed oldlinux (obsolete)
59+3. Gettimeofday -\> fpGettimeofday
60+4. Changed systemsleep for 64 bits systems
61+5. Some changes in timeval
62+6. Tested on AMD64 (linux)
63+
64+For any later changes, please see the Git commit log.
65+
66+### Dependencies / System Requirements
67+
68+- Nanosecond resolution is supported on Intel Pentium versions with a Timestamp Counter.
69+- Microsecond system clock is the default timebase.
70+
71+Tested on:
72+
73+- Pentium IV 3,2Ghz on Windows and Linux with great precision (~ 3,220,000,000 ticks per second)
74+- Pentium 233Mhz with Damn Small Linux. Works great with hardware clock.
75+- Mobile AMD 64 Athlon 3200+ on Windows XP Home (32 bit), Lazarus 9.13
76+- AMD 64 CPU, running 64 bit version of Ubuntu Linux, Lazarus 9.18.
77+- Intel i7-3770K, running 64-bit version of FreeBSD 9.1, using FPC 2.6.2
78+- ARM CPU using Raspberry Pi and FPC 2.6.2
79+
80+### Installation in Lazarus IDE
81+
82+- In Components/Open Package File, open etpackage.lpk
83+- Compile the package and close the package dialog
84+- In Components -\> Open Package File, open the etpackage_dsgn.lpk
85+- Compile the package.
86+- Click the Install button and let Lazarus rebuild
87+- Component will be in the System Palette (stopwatch-ruler icon)
88+
89+### Usage
90+
91+Drop 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.
92+
93+**If the timer is named ET**
94+
95+``` pascal
96+uses epiktimer;
97+
98+var
99+ ET: TEpikTimer;
100+
101+procedure InitTimer;
102+begin
103+ ET := TEpikTimer.Create(Application);
104+end;
105+
106+procedure InstrumentedCall;
107+Begin
108+ ET.Clear; // optional... timer is cleared at creation
109+ ET.Start;
110+ ExecuteFirstTimedSection;
111+ ET.Stop; // the timer is actually paused and can be restarted later
112+ TimedSection1:=ET.Elapsed; // store the elapsed in a global
113+ MakeAnUntimedOverheadCall; // not counted in the timer
114+ ET.Start; //resume the timer... continue accumulating ticks
115+ CallTimedSection2;
116+ TimedSection2:=ET.Elapsed; //timer keeps running... we've just sample it.
117+ CallTimedSection3;
118+ CallSomethingElse;
119+ TimedSection3:=ET.Elapsed; //keep counting... tap the elapsed
120+ CallTimedSection4;
121+ TimedSection4:=ET.Elapsed; //keep counting... tap the elapsed
122+ ET.clear // done... timer is stopped and zeroed
123+end;
124+```
125+
126+You 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:
127+
128+``` pascal
129+Function TimedExecution: Extended;
130+Var
131+ DiskAccessTime:TimerData;
132+Begin
133+ ET.Clear(DiskAccessTimer); // Declared timers *must* be cleared before use.
134+ ET.Start(DiskAccessTimer);
135+ ExecuteTheTimedSection;
136+ Result:=ET.Elapsed(DiskAccessTimer); // the timer keeps running...
137+ etc...
138+```
139+
140+One 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.
141+
142+``` pascal
143+DelayInSeconds := 8.5; // or any value
144+OldTime := ET.Elapsed;
145+
146+while ((ET.Elapsed - OldTime) < DelayInSeconds) do
147+begin
148+ ET.SystemSleep(10);
149+end;
150+
151+// DelayInSeconds has elapsed and now you can continue executing the code
152+```
153+
154+See etdemo.pas for additional examples of component usage
155+
156+#### EpikTimer as a profiler
157+
158+EpikTimer can be used to profile the speed of procedures:
159+
160+``` pascal
161+uses
162+ {$ifdef PROFILING}epiktimer,{$endif}
163+ ...
164+
165+type
166+ TMyClass = class
167+ private
168+ {$ifdef PROFILING}
169+ profiler: Tepiktimer;
170+ {$endif}
171+ ...
172+ end;
173+
174+implementation
175+
176+constructor TMyClass.Create(AOwner: TComponent);
177+begin
178+ inherited Create(AOwner);
179+
180+ ...
181+
182+ {$ifdef CARDROOM_PROFILING}
183+ profiler := TEpikTimer.Create(Self)
184+ {$endif}
185+end;
186+
187+procedure TMyClass.MethodToBeProfiled;
188+begin
189+ {$ifdef PROFILING}
190+ profiler.Clear;
191+ profiler.Start;
192+ {$endif}
193+ // do stuff
194+ {$ifdef PROFILING}
195+ OPDebugLn('TMyClass.MethodToBeProfiled ' + FloatToStr(profiler.Elapsed));
196+ {$endif}
197+end;
198+```
199+
200+### The ETDemo Application
201+
202+The 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! :)
203+
204+**Installation**
205+
206+- Open etdemo.lpi
207+- compile
208+- run
209+
210+### Console application
211+
212+If 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:
213+
214+` ET := TEpikTimer.Create(nil)`\
215+` ... your code here ...`\
216+` ET.Free;`
217+
218+### See also
219+
220+- [[doc:fcl/fptimer/index.html|FPTimer included with FPC/Lazarus]]
221+- [[Yet another Running Timer]]
222+
223+---
224+*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).*
225+Category: Components

Back to history