-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstack_vs_var_speed.dc
153 lines (132 loc) · 2.23 KB
/
stack_vs_var_speed.dc
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
"string.dc" import
1024 1024 16 * * const TESTCOUNT
"mykey" const :mykey
var myvar
1 myvar !
1 4 ! # 'raw' integer variable
######################
# The test functions #
######################
: time_stack
"Timing the stack: " print
clock
1
TESTCOUNT times
dup drop
again
drop
clock swap - 2 6 .rj cr
;
: time_svstack
"Timing the save stack: " print
clock
1 svpush
TESTCOUNT times
0 svpick drop
again
clock swap - 2 6 .rj cr
;
: time_locals { somevar }
"Timing local variables: " print
clock
TESTCOUNT times
somevar drop
again
clock swap - 2 6 .rj cr
;
: time_var_raw_int
"Timing variables using integers: " print
clock
TESTCOUNT times
4 @ drop
again
clock swap - 2 6 .rj cr
;
: time_var
"Timing normal named variables: " print
clock
TESTCOUNT times
myvar @ drop
again
clock swap - 2 6 .rj cr
;
: time_hash
"Timing hash lookup: " print
####################
# fill with values #
####################
1024 times
hex8token hex8token h!
again
1 :mykey h!
########################
# end fill with values #
########################
clock
TESTCOUNT times
:mykey h@ drop
again
clock swap - 2 6 .rj cr
;
: time_tree
"Timing tree lookup: " print
tmake drop
1024 times
0 hex8token hex8token t! drop
again
0 :mykey 23 t! drop
clock
TESTCOUNT times
0 :mykey t@ drop
again
clock swap - 2 6 .rj cr
;
: do_math_swap
"Timing math with swap: " print
clock
TESTCOUNT times
1 2 +
3 4 +
swap
/
drop
again
clock swap - 2 6 .rj cr
;
: do_math_save
"Timing math with svpush and svpop: " print
clock
TESTCOUNT times
1 2 + svpush
3 4 +
svpop
/
drop
again
clock swap - 2 6 .rj cr
;
: do_math_var
"Timing math with ! and @: " print
clock
TESTCOUNT times
1 2 + 0 !
3 4 +
0 @
/
drop
again
clock swap - 2 6 .rj cr
;
#################
# Run the tests #
#################
time_stack
time_svstack
5 time_locals
time_var_raw_int
time_var
time_hash
time_tree
do_math_swap
do_math_save
do_math_var