-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmeasure.fs
More file actions
32 lines (24 loc) · 707 Bytes
/
measure.fs
File metadata and controls
32 lines (24 loc) · 707 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
\g Start recording time
: lap ( -- r: -- d)
r> nstime 2>r >r ;
\g End recording time
: /lap ( -- d r: d -- )
r> nstime 2r> d- rot >r ;
\g Measure raw time required to execute xt including instrumentation.
: rawmeasured ( xt -- d )
lap execute /lap ;
\g Measure time required to execute xt.
: measured ( i*x xt -- j*x d )
['] noop rawmeasured 2drop \ warm up cache
rawmeasured
['] noop rawmeasured d- ;
\g Measure time required to execute word.
: measure ( "word" -- )
' measured ;
: .### # # # [char] . hold ;
\g Print nanoseconds in dotted format
: ns. ( d -- )
<# .### .### .### #s #> type space ;
\g Print measure
: .measure ( d -- )
." took " ns. ." nanoseconds" cr ;