You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/modules/tmr.md
+36Lines changed: 36 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -145,6 +145,42 @@ none
145
145
#### Returns
146
146
`nil`
147
147
148
+
## tmr.ccount()
149
+
150
+
Get value of CPU CCOUNT register which contains CPU ticks. The register is 32-bit and rolls over.
151
+
152
+
Converting the register's CPU ticks to us is done by dividing it to 80 or 160 (CPU80/CPU160) i.e. `tmr.ccount() / node.getcpufreq()`.
153
+
154
+
Register arithmetic works without need to account for roll over, unlike `tmr.now()`. Because of same reason when CCOUNT is having its 32nd bit set, it appears in Lua as negative number.
155
+
156
+
#### Syntax
157
+
`tmr.ccount()`
158
+
159
+
#### Returns
160
+
The current value of CCOUNT register.
161
+
162
+
#### Example
163
+
```lua
164
+
functiontimeIt(fnc, cnt)
165
+
localfunctionloopIt(f2)
166
+
localt0=tmr.ccount()
167
+
fori=1,cntdo
168
+
f2()
169
+
end
170
+
localt1=tmr.ccount()
171
+
returnmath.ceil((t1-t0)/cnt)
172
+
end
173
+
assert(type(fnc) =="function", "function to test missing")
0 commit comments