root/trunk/samples/speed.md

Revision 421, 3.7 kB (checked in by JarrettBillingsley, 3 weeks ago)

Improved class allocation speed by 35%. Wee. Partly due to string creation being much faster (don't have to validate a string if it's already in the interning table). Fixed a bug with parsing of instance parameter type constraints. Updated some tests.

It's also come to my attention that something like "time.Timer()" doesn't work currently because the method lookup expects Timer to be a function. Hm...

Line 
1 module speed;
2
3 /*
4 Taken from the Io speed test.
5 On my desktop.
6
7 Python reflIntMath       := 11.85
8 Python reflFloatMath     := 8.65
9
10 Python intMath           := 12.79
11 Python floatMath         := 9.14
12
13 Python localAccesses     := 26.74
14 Python localSets         := 24.51
15
16 Python slotAccesses      := 7.28
17 Python slotSets          := 8.21
18
19 Python blockActivations  := 2.76
20 Python instantiations    := 2.46
21 Python version           := "2.5.0 final 0"
22
23 // values in millions per second
24
25 MiniD reflIntMath        := 22.890733
26 MiniD reflFloatMath      := 22.586314
27
28 MiniD intMath            := 17.48588
29 MiniD floatMath          := 18.944848
30
31 MiniD localAccesses      := 38.003451
32 MiniD localSets          := 40.715949
33
34 MiniD slotAccesses       := 10.479171
35 MiniD slotSets           := 8.803344
36
37 MiniD blockActivations   := 3.809599
38 MiniD instantiations     := 1.265678
39
40 MiniD version            := "2.0 beta"
41
42 // values in millions per second
43 */
44
45 local t1
46 local oneMillion = 5_000_000
47
48 local function foo() {}
49
50 local class Tester
51 {
52     x
53
54     function beginTimer()
55         t1 = time.microTime()
56
57     function endTimer(s)
58     {
59         t1 = time.microTime() - t1
60         local mps = toFloat(oneMillion) / t1
61         writefln("MiniD {} := {:f5}", s, mps)
62     }
63
64     function testIntMath()
65     {
66         :beginTimer()
67         local x = 0
68         local y = 5
69         local z = 10
70
71         for(i: 0 .. oneMillion / 8)
72         {
73             x = y + z; x = y + z; x = y + z; x = y + z
74             x = y + z; x = y + z; x = y + z; x = y + z
75         }
76
77         :endTimer("intMath\t\t")
78     }
79
80     function testFloatMath()
81     {
82         :beginTimer()
83         local x = 0.0
84         local y = 5.0
85         local z = 10.0
86
87         for(i: 0 .. oneMillion / 8)
88         {
89             x = y + z; x = y + z; x = y + z; x = y + z
90             x = y + z; x = y + z; x = y + z; x = y + z
91         }
92
93         :endTimer("floatMath\t\t")
94     }
95
96     function testReflIntMath()
97     {
98         :beginTimer()
99         local x = 0
100         local y = 5
101
102         for(i: 0 .. oneMillion / 8)
103         {
104             x += y; x += y; x += y; x += y
105             x += y; x += y; x += y; x += y
106         }
107
108         :endTimer("reflIntMath\t")
109     }
110
111     function testReflFloatMath()
112     {
113         :beginTimer()
114         local x = 0.0
115         local y = 5.0
116
117         for(i: 0 .. oneMillion / 8)
118         {
119             x += y; x += y; x += y; x += y
120             x += y; x += y; x += y; x += y
121         }
122
123         :endTimer("reflFloatMath\t")
124     }
125
126     function testLocals()
127     {
128         :beginTimer()
129         local v = 1
130         local y
131
132         for(i : 0 .. oneMillion / 8)
133         {
134             y = v; y = v;  y = v; y = v
135             y = v; y = v;  y = v; y = v
136         }
137
138         :endTimer("localAccesses\t")
139     }
140
141     function testSetLocals()
142     {
143         :beginTimer()
144         local v = 1
145
146         for(i : 0 .. oneMillion / 8)
147         {
148             v = 1; v = 2; v = 3; v = 4
149             v = 1; v = 2; v = 3; v = 4
150         }
151
152         :endTimer("localSets\t\t")
153     }
154
155     function testSlot()
156     {
157         :beginTimer()
158         :x = 1
159         local y
160
161         for(i : 0 .. oneMillion / 8)
162         {
163             y = :x; y = :x; y = :x; y = :x
164             y = :x; y = :x; y = :x; y = :x
165         }
166
167         :endTimer("slotAccesses\t")
168     }
169
170     function testSetSlot()
171     {
172         :beginTimer()
173
174         for(i : 0 .. oneMillion / 8)
175         {
176             :x = 1; :x = 2; :x = 3; :x = 4
177             :x = 1; :x = 2; :x = 3; :x = 4;
178         }
179
180         :endTimer("slotSets\t\t")
181     }
182
183     function testBlock()
184     {
185         :beginTimer()
186
187         for(i : 0 .. oneMillion / 8)
188         {
189             foo(); foo(); foo(); foo()
190             foo(); foo(); foo(); foo()
191         }
192
193         :endTimer("blockActivations\t")
194     }
195
196     function testInstantiations()
197     {
198         :beginTimer()
199
200         for(i : 0 .. oneMillion / 8)
201         {
202             Tester(); Tester(); Tester(); Tester()
203             Tester(); Tester(); Tester(); Tester()
204         }
205
206         :endTimer("instantiations\t")
207     }
208
209     function test()
210     {
211         :testReflIntMath()
212         :testReflFloatMath()
213         writefln()
214         :testIntMath()
215         :testFloatMath()
216         writefln()
217         :testLocals()
218         :testSetLocals()
219         writefln()
220         :testSlot()
221         :testSetSlot()
222         writefln()
223         :testBlock()
224         :testInstantiations()
225
226         writefln()
227         writefln("MiniD version\t\t := \"2.0 beta\"")
228         writefln()
229         writefln("// values in millions per second")
230     }
231 }
232
233 function main()
234     Tester.test()
Note: See TracBrowser for help on using the browser.