1447
|
1 |
"{ Package: 'stx:goodies/regression/benchmarks' }"
|
552
|
2 |
|
|
3 |
Object subclass:#CollectionBenchmarks
|
|
4 |
instanceVariableNames:''
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'benchmarks-Collections'
|
|
8 |
!
|
|
9 |
|
|
10 |
|
1538
|
11 |
!CollectionBenchmarks class methodsFor:'standalone run'!
|
|
12 |
|
|
13 |
main
|
|
14 |
"to run from the commandline, type
|
|
15 |
stx -I --load CollectionBenchmarks.st --run CollectionBenchmarks
|
|
16 |
"
|
|
17 |
self collectionTimings
|
|
18 |
! !
|
|
19 |
|
552
|
20 |
!CollectionBenchmarks class methodsFor:'sorted collections'!
|
|
21 |
|
|
22 |
collectionTimings
|
|
23 |
|N randomNumbers|
|
|
24 |
|
|
25 |
N := 100000.
|
|
26 |
randomNumbers := (1 to:N) collect:[:i | Random nextInteger].
|
|
27 |
ObjectMemory garbageCollect.
|
|
28 |
|
|
29 |
#(SortedCollection AATree BinaryTree) do:[:className |
|
1447
|
30 |
|class doBench coll t seq|
|
552
|
31 |
|
1447
|
32 |
class := Smalltalk classNamed:className.
|
552
|
33 |
|
1447
|
34 |
doBench := [:class |
|
|
35 |
|coll t|
|
552
|
36 |
|
1447
|
37 |
t := Time millisecondsToRun:[
|
|
38 |
coll := class new.
|
|
39 |
randomNumbers do:[:each | coll add:each]
|
|
40 |
].
|
|
41 |
Transcript show:'Time to insert random '; show:N; show:' individually into ',class name,': '; show:t; showCR:'ms'.
|
|
42 |
coll
|
|
43 |
].
|
552
|
44 |
|
1447
|
45 |
ObjectMemory garbageCollect.
|
|
46 |
doBench value:class.
|
|
47 |
ObjectMemory garbageCollect.
|
552
|
48 |
|
1447
|
49 |
doBench := [:class |
|
|
50 |
|coll t|
|
552
|
51 |
|
1447
|
52 |
t := Time millisecondsToRun:[
|
|
53 |
coll := class new.
|
|
54 |
coll addAll:randomNumbers
|
|
55 |
].
|
|
56 |
Transcript show:'Time to insert random '; show:N; show:' en-bloque into ',class name,': '; show:t; showCR:'ms'.
|
|
57 |
coll
|
|
58 |
].
|
552
|
59 |
|
1447
|
60 |
ObjectMemory garbageCollect.
|
|
61 |
doBench value:class.
|
|
62 |
ObjectMemory garbageCollect.
|
552
|
63 |
|
1447
|
64 |
doBench := [:class |
|
|
65 |
|coll t|
|
552
|
66 |
|
1447
|
67 |
t := Time millisecondsToRun:[
|
|
68 |
coll := class new.
|
|
69 |
(1 to:N) do:[:each | coll add:each].
|
|
70 |
].
|
|
71 |
Transcript show:'Time to insert in order '; show:N; show:' individually into ',class name,': '; show:t; showCR:'ms'.
|
|
72 |
coll
|
|
73 |
].
|
552
|
74 |
|
1447
|
75 |
ObjectMemory garbageCollect.
|
|
76 |
doBench value:class.
|
|
77 |
ObjectMemory garbageCollect.
|
552
|
78 |
|
1447
|
79 |
doBench := [:class |
|
|
80 |
|coll t|
|
552
|
81 |
|
1447
|
82 |
t := Time millisecondsToRun:[
|
|
83 |
coll := class new.
|
|
84 |
coll addAll:(1 to:N).
|
|
85 |
].
|
|
86 |
Transcript show:'Time to insert in order '; show:N; show:' en-bloque into ',class name,': '; show:t; showCR:'ms'.
|
|
87 |
coll
|
|
88 |
].
|
552
|
89 |
|
1447
|
90 |
ObjectMemory garbageCollect.
|
|
91 |
doBench value:class.
|
|
92 |
ObjectMemory garbageCollect.
|
552
|
93 |
|
1447
|
94 |
doBench := [:class |
|
|
95 |
|coll t|
|
552
|
96 |
|
1447
|
97 |
t := Time millisecondsToRun:[
|
|
98 |
coll := class new.
|
|
99 |
(N downTo:1) do:[:each | coll add:each].
|
|
100 |
].
|
|
101 |
Transcript show:'Time to insert in reverse order '; show:N; show:' individually into ',class name,': '; show:t; showCR:'ms'.
|
|
102 |
coll
|
|
103 |
].
|
552
|
104 |
|
1447
|
105 |
ObjectMemory garbageCollect.
|
|
106 |
doBench value:class.
|
|
107 |
ObjectMemory garbageCollect.
|
552
|
108 |
|
1447
|
109 |
doBench := [:class |
|
|
110 |
|coll t|
|
552
|
111 |
|
1447
|
112 |
t := Time millisecondsToRun:[
|
|
113 |
coll := class new.
|
|
114 |
coll addAll:(N downTo:1).
|
|
115 |
].
|
|
116 |
Transcript show:'Time to insert in reverse order '; show:N; show:' en-bloque into ',class name,': '; show:t; showCR:'ms'.
|
|
117 |
coll
|
|
118 |
].
|
552
|
119 |
|
1447
|
120 |
ObjectMemory garbageCollect.
|
|
121 |
doBench value:class.
|
|
122 |
ObjectMemory garbageCollect.
|
552
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
1447
|
127 |
coll := class new.
|
|
128 |
coll addAll:randomNumbers.
|
552
|
129 |
|
1447
|
130 |
t := Time millisecondsToRun:[
|
|
131 |
coll removeAll:randomNumbers.
|
|
132 |
].
|
|
133 |
Transcript show:'Time to remove in random order '; show:N; show:' from ',class name,': '; show:t; showCR:'ms'.
|
|
134 |
self assert:(coll isEmpty).
|
|
135 |
ObjectMemory garbageCollect.
|
552
|
136 |
|
|
137 |
|
1447
|
138 |
coll := class new.
|
|
139 |
coll addAll:randomNumbers.
|
|
140 |
seq := randomNumbers copy sort.
|
552
|
141 |
|
1447
|
142 |
t := Time millisecondsToRun:[
|
|
143 |
coll removeAll:seq.
|
|
144 |
].
|
|
145 |
Transcript show:'Time to remove in order '; show:N; show:' from ',class name,': '; show:t; showCR:'ms'.
|
|
146 |
self assert:(coll isEmpty).
|
|
147 |
ObjectMemory garbageCollect.
|
552
|
148 |
|
1447
|
149 |
coll := class new.
|
|
150 |
coll addAll:randomNumbers.
|
|
151 |
seq := randomNumbers copy sort reverse.
|
552
|
152 |
|
1447
|
153 |
t := Time millisecondsToRun:[
|
|
154 |
coll removeAll:seq.
|
|
155 |
].
|
|
156 |
Transcript show:'Time to remove in reverse order '; show:N; show:' from ',class name,': '; show:t; showCR:'ms'.
|
|
157 |
self assert:(coll isEmpty).
|
|
158 |
ObjectMemory garbageCollect.
|
552
|
159 |
|
1447
|
160 |
Transcript cr.
|
552
|
161 |
].
|
|
162 |
!
|
|
163 |
|
|
164 |
documentation
|
|
165 |
"
|
|
166 |
Time to insert random 100000 individually into SortedCollection: 6037ms
|
|
167 |
Time to insert random 100000 en-bloque into SortedCollection: 172ms
|
|
168 |
Time to insert in order 100000 individually into SortedCollection: 31ms
|
|
169 |
Time to insert in order 100000 en-bloque into SortedCollection: 125ms
|
|
170 |
Time to insert in reverse order 100000 individually into SortedCollection: 93ms
|
|
171 |
Time to insert in reverse order 100000 en-bloque into SortedCollection: 125ms
|
|
172 |
Time to remove in random order 100000 from SortedCollection: 6380ms
|
|
173 |
Time to remove in order 100000 from SortedCollection: 109ms
|
|
174 |
Time to remove in reverse order 100000 from SortedCollection: 125ms
|
|
175 |
|
|
176 |
Time to insert random 100000 individually into AATree: 281ms
|
|
177 |
Time to insert random 100000 en-bloque into AATree: 265ms
|
|
178 |
Time to insert in order 100000 individually into AATree: 281ms
|
|
179 |
Time to insert in order 100000 en-bloque into AATree: 328ms
|
|
180 |
Time to insert in reverse order 100000 individually into AATree: 203ms
|
|
181 |
Time to insert in reverse order 100000 en-bloque into AATree: 218ms
|
|
182 |
Time to remove in random order 100000 from AATree: 452ms
|
|
183 |
Time to remove in order 100000 from AATree: 312ms
|
|
184 |
Time to remove in reverse order 100000 from AATree: 499ms
|
|
185 |
|
|
186 |
Time to insert random 100000 individually into BinaryTree: 156ms
|
|
187 |
Time to insert random 100000 en-bloque into BinaryTree: 156ms
|
|
188 |
Time to insert in order 100000 individually into BinaryTree: 195921ms
|
|
189 |
Time to insert in order 100000 en-bloque into BinaryTree: 205266ms
|
|
190 |
Time to insert in reverse order 100000 individually into BinaryTree: 202271ms
|
|
191 |
Time to insert in reverse order 100000 en-bloque into BinaryTree: 197684ms
|
|
192 |
Time to remove in random order 100000 from BinaryTree: 234ms
|
|
193 |
Time to remove in order 100000 from BinaryTree: 78ms
|
|
194 |
Time to remove in reverse order 100000 from BinaryTree: 78ms
|
1538
|
195 |
|
|
196 |
on a 2010 powerbook (2.1Ghz 86_64)
|
|
197 |
Time to insert random 100000 individually into SortedCollection: 1390ms
|
|
198 |
Time to insert random 100000 en-bloque into SortedCollection: 50ms
|
|
199 |
Time to insert in order 100000 individually into SortedCollection: 20ms
|
|
200 |
Time to insert in order 100000 en-bloque into SortedCollection: 20ms
|
|
201 |
Time to insert in reverse order 100000 individually into SortedCollection: 40ms
|
|
202 |
Time to insert in reverse order 100000 en-bloque into SortedCollection: 40ms
|
|
203 |
Time to remove in random order 100000 from SortedCollection: 1370ms
|
|
204 |
Time to remove in order 100000 from SortedCollection: 40ms
|
|
205 |
Time to remove in reverse order 100000 from SortedCollection: 40ms
|
|
206 |
|
|
207 |
Time to insert random 100000 individually into AATree: 170ms
|
|
208 |
Time to insert random 100000 en-bloque into AATree: 170ms
|
|
209 |
Time to insert in order 100000 individually into AATree: 170ms
|
|
210 |
Time to insert in order 100000 en-bloque into AATree: 150ms
|
|
211 |
Time to insert in reverse order 100000 individually into AATree: 130ms
|
|
212 |
Time to insert in reverse order 100000 en-bloque into AATree: 120ms
|
|
213 |
Time to remove in random order 100000 from AATree: 310ms
|
|
214 |
Time to remove in order 100000 from AATree: 200ms
|
|
215 |
Time to remove in reverse order 100000 from AATree: 260ms
|
|
216 |
|
|
217 |
Time to insert random 100000 individually into BinaryTree: 110ms
|
|
218 |
Time to insert random 100000 en-bloque into BinaryTree: 100ms
|
|
219 |
Time to insert in order 100000 individually into BinaryTree: 77260ms
|
|
220 |
Time to insert in order 100000 en-bloque into BinaryTree: 78420ms
|
|
221 |
Time to insert in reverse order 100000 individually into BinaryTree: 78830ms
|
|
222 |
Time to insert in reverse order 100000 en-bloque into BinaryTree: 79020ms
|
|
223 |
Time to remove in random order 100000 from BinaryTree: 160ms
|
|
224 |
Time to remove in order 100000 from BinaryTree: 50ms
|
|
225 |
Time to remove in reverse order 100000 from BinaryTree: 40ms
|
552
|
226 |
"
|
|
227 |
!
|
|
228 |
|
|
229 |
test_Btree
|
|
230 |
|coll sc randomNumbers|
|
|
231 |
|
|
232 |
randomNumbers := (1 to:1000) collect:[:i |Random nextInteger].
|
|
233 |
|
|
234 |
sc := SortedCollection new.
|
|
235 |
sc addAll:randomNumbers.
|
|
236 |
|
|
237 |
coll := BinaryTree new.
|
|
238 |
coll addAll:randomNumbers.
|
|
239 |
|
|
240 |
randomNumbers do:[:each |
|
|
241 |
"/ Transcript showCR:'-----------'.
|
|
242 |
"/ Transcript showCR:(coll instVarNamed:'treeRoot').
|
|
243 |
"/ Transcript showCR:each.
|
1447
|
244 |
coll remove:each.
|
|
245 |
sc remove:each.
|
|
246 |
self assert:(sc asOrderedCollection = coll asOrderedCollection).
|
552
|
247 |
].
|
|
248 |
! !
|
|
249 |
|
|
250 |
!CollectionBenchmarks class methodsFor:'documentation'!
|
|
251 |
|
|
252 |
version
|
|
253 |
^ '$Header$'
|
|
254 |
! !
|