Skip to content

Commit 296cb6b

Browse files
committed
Updated the readme for humans.
1 parent 54a6e42 commit 296cb6b

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

README.md

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,48 @@
11
# Timer
22

3-
This is a simple timing utility for CFML applications to assess code execution speed.
3+
Timer is a simple timing utility for CFML applications to assess code execution speed.
44

5-
See the unit test in /test/unit/util/TimerTest.cfc for some example usage.
5+
## Features
6+
7+
- Keeps track of multiple timing counters
8+
- The order of the timing counters is preserved for logical display in statistics
9+
- Supports arbitrary nesting of timing counters
10+
11+
## Usage
12+
13+
The following is a simple Timer example. You can also see `/test/unit/util/TimerTest.cfc` for a runnable example.
14+
15+
Create an instance of Timer.
16+
```
17+
<cfset var timer = createObject("component", "model.util.Timer").init()/>
18+
```
19+
Create a named timing counter. A batch of timing counters can be created before starting any of them; this sets the order of timing counters before collecting data. This step can be skipped if you'd like to create the timing counter and start it in one call.
20+
```
21+
<cfset timer.new("transmogrifier total time")/>
22+
```
23+
Begin the named timing counter before executing the code to be timed. If the timing counter doesn't already exist, it will be created.
24+
```
25+
<cfset timer.begin("transmogrifier total time")/>
26+
<cfset transmogrifier.execute("Susie", "bowl of chowder")/>
27+
```
28+
Upon completion of the code being timed, end the named timing counter.
29+
```
30+
<cfset timer.end("transmogrifier total time")/>
31+
```
32+
Collect the statistics of all named timing counters.
33+
```
34+
<cfset debug(timer.stats())/>
35+
```
36+
The result will be an array of structures, each of which have the name of the counter and the number of milliseconds counted. For example:
37+
```json
38+
[
39+
{
40+
"name": "transmogrifier total time",
41+
"time": 39922
42+
}
43+
]
44+
```
45+
46+
## Future Enhancements
47+
48+
I'd like to add a nice mechanism for pause/resume so that some execution could be excluded using an intuitive API.

0 commit comments

Comments
 (0)