-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbenched.fs
More file actions
108 lines (88 loc) · 2.02 KB
/
benched.fs
File metadata and controls
108 lines (88 loc) · 2.02 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
\ galope/benched.fs
\ This file is part of Galope
\ http://programandala.net/en.program.galope.html
\ Author: Marcos Cruz (programandala.net), 2016, 2017.
\ ==============================================================
\ Credits
\ Code adapted from Solo Forth. The Solo Forth version was
\ adapted from Forth Dimensions (volume 17, number 4 page 11,
\ 1995-11).
\ ==============================================================
2variable bench0
: bench{ ( -- ) utime bench0 2! ;
\ doc{
\
\ bench{ ( -- )
\
\ Mark the start of a benchmark.
\
\ See also: `}bench`, `}bench.`.
\
\ }doc
: }bench ( -- d ) utime bench0 2@ d- ;
\ doc{
\
\ }bench ( -- d )
\
\ Mark the end of a benchmark that was started by `bench{`
\ and leave the result _d_ in microseconds.
\
\ See also: `}bench.`.
\
\ }doc
: bench. ( d -- ) d. ." ms" ;
\ doc{
\
\ bench. ( d -- )
\
\ Display the result _d_ in microseconds of a benchmark, left
\ by `}bench` or `benched`.
\
\ See also: `bench{`, `}bench.`.
\
\ }doc
: }bench. ( -- ) }bench bench. ;
\ doc{
\
\ }bench. ( -- )
\
\ Mark the end of a benchmark that was started by `bench{`
\ and display the result in microseconds.
\
\ See also: `}bench`, `bench.`.
\
\ }doc
: benched ( xt n -- d )
bench{ 0 do dup execute loop }bench rot drop ;
\ doc{
\
\ benched ( xt n -- d )
\
\ Benchmark _xt_ by executing it _n_ times.
\
\ NOTE: A copy of _xt_ is on the stack when _xt_ is executed.
\
\ See also: `bench{`, `}bench`.
\
\ }doc
: benched. ( xt n -- )
bench{ 0 do dup execute loop }bench. drop ;
\ doc{
\
\ benched. ( xt n -- )
\
\ Benchmark _xt_ by executing it _n_ times and display the
\ result in microseconds.
\
\ NOTE: A copy of _xt_ is on the stack when _xt_ is executed.
\
\ See also: `bench{`, `}bench.`.
\
\ }doc
\ ==============================================================
\ Change log
\ 2016-03-15: Added.
\
\ 2017-08-17: Update change log layout.
\
\ 2017-11-28: Improve documentation.