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 |
|
|
11 |
!CollectionBenchmarks class methodsFor:'sorted collections'!
|
|
12 |
|
|
13 |
collectionTimings
|
|
14 |
|N randomNumbers|
|
|
15 |
|
|
16 |
N := 100000.
|
|
17 |
randomNumbers := (1 to:N) collect:[:i | Random nextInteger].
|
|
18 |
ObjectMemory garbageCollect.
|
|
19 |
|
|
20 |
#(SortedCollection AATree BinaryTree) do:[:className |
|
1447
|
21 |
|class doBench coll t seq|
|
552
|
22 |
|
1447
|
23 |
class := Smalltalk classNamed:className.
|
552
|
24 |
|
1447
|
25 |
doBench := [:class |
|
|
26 |
|coll t|
|
552
|
27 |
|
1447
|
28 |
t := Time millisecondsToRun:[
|
|
29 |
coll := class new.
|
|
30 |
randomNumbers do:[:each | coll add:each]
|
|
31 |
].
|
|
32 |
Transcript show:'Time to insert random '; show:N; show:' individually into ',class name,': '; show:t; showCR:'ms'.
|
|
33 |
coll
|
|
34 |
].
|
552
|
35 |
|
1447
|
36 |
ObjectMemory garbageCollect.
|
|
37 |
doBench value:class.
|
|
38 |
ObjectMemory garbageCollect.
|
552
|
39 |
|
1447
|
40 |
doBench := [:class |
|
|
41 |
|coll t|
|
552
|
42 |
|
1447
|
43 |
t := Time millisecondsToRun:[
|
|
44 |
coll := class new.
|
|
45 |
coll addAll:randomNumbers
|
|
46 |
].
|
|
47 |
Transcript show:'Time to insert random '; show:N; show:' en-bloque into ',class name,': '; show:t; showCR:'ms'.
|
|
48 |
coll
|
|
49 |
].
|
552
|
50 |
|
1447
|
51 |
ObjectMemory garbageCollect.
|
|
52 |
doBench value:class.
|
|
53 |
ObjectMemory garbageCollect.
|
552
|
54 |
|
1447
|
55 |
doBench := [:class |
|
|
56 |
|coll t|
|
552
|
57 |
|
1447
|
58 |
t := Time millisecondsToRun:[
|
|
59 |
coll := class new.
|
|
60 |
(1 to:N) do:[:each | coll add:each].
|
|
61 |
].
|
|
62 |
Transcript show:'Time to insert in order '; show:N; show:' individually into ',class name,': '; show:t; showCR:'ms'.
|
|
63 |
coll
|
|
64 |
].
|
552
|
65 |
|
1447
|
66 |
ObjectMemory garbageCollect.
|
|
67 |
doBench value:class.
|
|
68 |
ObjectMemory garbageCollect.
|
552
|
69 |
|
1447
|
70 |
doBench := [:class |
|
|
71 |
|coll t|
|
552
|
72 |
|
1447
|
73 |
t := Time millisecondsToRun:[
|
|
74 |
coll := class new.
|
|
75 |
coll addAll:(1 to:N).
|
|
76 |
].
|
|
77 |
Transcript show:'Time to insert in order '; show:N; show:' en-bloque into ',class name,': '; show:t; showCR:'ms'.
|
|
78 |
coll
|
|
79 |
].
|
552
|
80 |
|
1447
|
81 |
ObjectMemory garbageCollect.
|
|
82 |
doBench value:class.
|
|
83 |
ObjectMemory garbageCollect.
|
552
|
84 |
|
1447
|
85 |
doBench := [:class |
|
|
86 |
|coll t|
|
552
|
87 |
|
1447
|
88 |
t := Time millisecondsToRun:[
|
|
89 |
coll := class new.
|
|
90 |
(N downTo:1) do:[:each | coll add:each].
|
|
91 |
].
|
|
92 |
Transcript show:'Time to insert in reverse order '; show:N; show:' individually into ',class name,': '; show:t; showCR:'ms'.
|
|
93 |
coll
|
|
94 |
].
|
552
|
95 |
|
1447
|
96 |
ObjectMemory garbageCollect.
|
|
97 |
doBench value:class.
|
|
98 |
ObjectMemory garbageCollect.
|
552
|
99 |
|
1447
|
100 |
doBench := [:class |
|
|
101 |
|coll t|
|
552
|
102 |
|
1447
|
103 |
t := Time millisecondsToRun:[
|
|
104 |
coll := class new.
|
|
105 |
coll addAll:(N downTo:1).
|
|
106 |
].
|
|
107 |
Transcript show:'Time to insert in reverse order '; show:N; show:' en-bloque into ',class name,': '; show:t; showCR:'ms'.
|
|
108 |
coll
|
|
109 |
].
|
552
|
110 |
|
1447
|
111 |
ObjectMemory garbageCollect.
|
|
112 |
doBench value:class.
|
|
113 |
ObjectMemory garbageCollect.
|
552
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
1447
|
118 |
coll := class new.
|
|
119 |
coll addAll:randomNumbers.
|
552
|
120 |
|
1447
|
121 |
t := Time millisecondsToRun:[
|
|
122 |
coll removeAll:randomNumbers.
|
|
123 |
].
|
|
124 |
Transcript show:'Time to remove in random order '; show:N; show:' from ',class name,': '; show:t; showCR:'ms'.
|
|
125 |
self assert:(coll isEmpty).
|
|
126 |
ObjectMemory garbageCollect.
|
552
|
127 |
|
|
128 |
|
1447
|
129 |
coll := class new.
|
|
130 |
coll addAll:randomNumbers.
|
|
131 |
seq := randomNumbers copy sort.
|
552
|
132 |
|
1447
|
133 |
t := Time millisecondsToRun:[
|
|
134 |
coll removeAll:seq.
|
|
135 |
].
|
|
136 |
Transcript show:'Time to remove in order '; show:N; show:' from ',class name,': '; show:t; showCR:'ms'.
|
|
137 |
self assert:(coll isEmpty).
|
|
138 |
ObjectMemory garbageCollect.
|
552
|
139 |
|
1447
|
140 |
coll := class new.
|
|
141 |
coll addAll:randomNumbers.
|
|
142 |
seq := randomNumbers copy sort reverse.
|
552
|
143 |
|
1447
|
144 |
t := Time millisecondsToRun:[
|
|
145 |
coll removeAll:seq.
|
|
146 |
].
|
|
147 |
Transcript show:'Time to remove in reverse order '; show:N; show:' from ',class name,': '; show:t; showCR:'ms'.
|
|
148 |
self assert:(coll isEmpty).
|
|
149 |
ObjectMemory garbageCollect.
|
552
|
150 |
|
1447
|
151 |
Transcript cr.
|
552
|
152 |
].
|
|
153 |
!
|
|
154 |
|
|
155 |
documentation
|
|
156 |
"
|
|
157 |
Time to insert random 100000 individually into SortedCollection: 6037ms
|
|
158 |
Time to insert random 100000 en-bloque into SortedCollection: 172ms
|
|
159 |
Time to insert in order 100000 individually into SortedCollection: 31ms
|
|
160 |
Time to insert in order 100000 en-bloque into SortedCollection: 125ms
|
|
161 |
Time to insert in reverse order 100000 individually into SortedCollection: 93ms
|
|
162 |
Time to insert in reverse order 100000 en-bloque into SortedCollection: 125ms
|
|
163 |
Time to remove in random order 100000 from SortedCollection: 6380ms
|
|
164 |
Time to remove in order 100000 from SortedCollection: 109ms
|
|
165 |
Time to remove in reverse order 100000 from SortedCollection: 125ms
|
|
166 |
|
|
167 |
Time to insert random 100000 individually into AATree: 281ms
|
|
168 |
Time to insert random 100000 en-bloque into AATree: 265ms
|
|
169 |
Time to insert in order 100000 individually into AATree: 281ms
|
|
170 |
Time to insert in order 100000 en-bloque into AATree: 328ms
|
|
171 |
Time to insert in reverse order 100000 individually into AATree: 203ms
|
|
172 |
Time to insert in reverse order 100000 en-bloque into AATree: 218ms
|
|
173 |
Time to remove in random order 100000 from AATree: 452ms
|
|
174 |
Time to remove in order 100000 from AATree: 312ms
|
|
175 |
Time to remove in reverse order 100000 from AATree: 499ms
|
|
176 |
|
|
177 |
Time to insert random 100000 individually into BinaryTree: 156ms
|
|
178 |
Time to insert random 100000 en-bloque into BinaryTree: 156ms
|
|
179 |
Time to insert in order 100000 individually into BinaryTree: 195921ms
|
|
180 |
Time to insert in order 100000 en-bloque into BinaryTree: 205266ms
|
|
181 |
Time to insert in reverse order 100000 individually into BinaryTree: 202271ms
|
|
182 |
Time to insert in reverse order 100000 en-bloque into BinaryTree: 197684ms
|
|
183 |
Time to remove in random order 100000 from BinaryTree: 234ms
|
|
184 |
Time to remove in order 100000 from BinaryTree: 78ms
|
|
185 |
Time to remove in reverse order 100000 from BinaryTree: 78ms
|
|
186 |
"
|
|
187 |
!
|
|
188 |
|
|
189 |
test_Btree
|
|
190 |
|coll sc randomNumbers|
|
|
191 |
|
|
192 |
randomNumbers := (1 to:1000) collect:[:i |Random nextInteger].
|
|
193 |
|
|
194 |
sc := SortedCollection new.
|
|
195 |
sc addAll:randomNumbers.
|
|
196 |
|
|
197 |
coll := BinaryTree new.
|
|
198 |
coll addAll:randomNumbers.
|
|
199 |
|
|
200 |
randomNumbers do:[:each |
|
|
201 |
"/ Transcript showCR:'-----------'.
|
|
202 |
"/ Transcript showCR:(coll instVarNamed:'treeRoot').
|
|
203 |
"/ Transcript showCR:each.
|
1447
|
204 |
coll remove:each.
|
|
205 |
sc remove:each.
|
|
206 |
self assert:(sc asOrderedCollection = coll asOrderedCollection).
|
552
|
207 |
].
|
|
208 |
! !
|
|
209 |
|
|
210 |
!CollectionBenchmarks class methodsFor:'documentation'!
|
|
211 |
|
|
212 |
version
|
|
213 |
^ '$Header$'
|
|
214 |
! !
|