1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Diagnostics;
|
---|
24 | using System.Drawing;
|
---|
25 | using System.Threading;
|
---|
26 | using HeuristicLab.Common;
|
---|
27 | using HeuristicLab.Core;
|
---|
28 | using HeuristicLab.Data;
|
---|
29 | using HeuristicLab.Optimization;
|
---|
30 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
31 |
|
---|
32 | namespace HeuristicLab.Algorithms.Benchmarks {
|
---|
33 | [Item("Dhrystone Algorithm", "Dhrystone benchmarking algorithm.")]
|
---|
34 | [StorableClass]
|
---|
35 | public class DhrystoneBenchmark : IBenchmark {
|
---|
36 | [Storable]
|
---|
37 | private byte[][] chunk;
|
---|
38 | public byte[][] ChunkData {
|
---|
39 | get { return chunk; }
|
---|
40 | set { chunk = value; }
|
---|
41 | }
|
---|
42 |
|
---|
43 | [Storable]
|
---|
44 | private TimeSpan timeLimit;
|
---|
45 | public TimeSpan TimeLimit {
|
---|
46 | get { return timeLimit; }
|
---|
47 | set { timeLimit = value; }
|
---|
48 | }
|
---|
49 |
|
---|
50 | private bool stopBenchmark;
|
---|
51 |
|
---|
52 | private CancellationToken cancellationToken;
|
---|
53 |
|
---|
54 | public string ItemName {
|
---|
55 | get { return ItemAttribute.GetName(this.GetType()); }
|
---|
56 | }
|
---|
57 |
|
---|
58 | public string ItemDescription {
|
---|
59 | get { return ItemAttribute.GetDescription(this.GetType()); }
|
---|
60 | }
|
---|
61 |
|
---|
62 | public Version ItemVersion {
|
---|
63 | get { return ItemAttribute.GetVersion(this.GetType()); }
|
---|
64 | }
|
---|
65 |
|
---|
66 | public Image ItemImage {
|
---|
67 | get { return HeuristicLab.Common.Resources.VSImageLibrary.Event; }
|
---|
68 | }
|
---|
69 |
|
---|
70 | #region Benchmark Fields
|
---|
71 |
|
---|
72 | private const int Ident_1 = 0;
|
---|
73 | private const int Ident_2 = 1;
|
---|
74 | private const int Ident_3 = 2;
|
---|
75 | private const int Ident_4 = 3;
|
---|
76 | private const int Ident_5 = 4;
|
---|
77 |
|
---|
78 | private Record_Type Record_Glob;
|
---|
79 | private Record_Type Next_Record_Glob;
|
---|
80 |
|
---|
81 | private int Int_Glob;
|
---|
82 | private Boolean Bool_Glob;
|
---|
83 |
|
---|
84 | private char Char_Glob_1;
|
---|
85 | private char Char_Glob_2;
|
---|
86 |
|
---|
87 | private int[] Array_Glob_1 = new int[128];
|
---|
88 | private int[][] Array_Glob_2 = new int[128][];
|
---|
89 |
|
---|
90 | private Record_Type First_Record = new Record_Type();
|
---|
91 | private Record_Type Second_Record = new Record_Type();
|
---|
92 |
|
---|
93 | private long Default_Number_Of_Runs = 10000000;
|
---|
94 |
|
---|
95 | #endregion
|
---|
96 |
|
---|
97 | #region Costructors
|
---|
98 |
|
---|
99 | [StorableConstructor]
|
---|
100 | public DhrystoneBenchmark(bool deserializing) { }
|
---|
101 |
|
---|
102 | public DhrystoneBenchmark() { }
|
---|
103 |
|
---|
104 | protected DhrystoneBenchmark(DhrystoneBenchmark original, Cloner cloner) {
|
---|
105 | cloner.RegisterClonedObject(original, this);
|
---|
106 | }
|
---|
107 |
|
---|
108 | #endregion
|
---|
109 |
|
---|
110 | #region Benchmark Methods
|
---|
111 | // implementation based on Java version: http://www.okayan.jp/DhrystoneApplet/dhry_src.jar
|
---|
112 |
|
---|
113 | public void Run(CancellationToken token, ResultCollection results) {
|
---|
114 | cancellationToken = token;
|
---|
115 | stopBenchmark = false;
|
---|
116 |
|
---|
117 | int Int_Loc_1;
|
---|
118 | int Int_Loc_2;
|
---|
119 | int Int_Loc_3;
|
---|
120 |
|
---|
121 | int[] Int_Loc_1_Ref = new int[1];
|
---|
122 | int[] Int_Loc_3_Ref = new int[1];
|
---|
123 |
|
---|
124 | char Char_Index;
|
---|
125 | int[] Enum_Loc = new int[1];
|
---|
126 |
|
---|
127 | string String_Loc_1;
|
---|
128 | string String_Loc_2;
|
---|
129 |
|
---|
130 | long total_time;
|
---|
131 |
|
---|
132 | long Run_Index;
|
---|
133 |
|
---|
134 | Next_Record_Glob = Second_Record;
|
---|
135 | Record_Glob = First_Record;
|
---|
136 |
|
---|
137 | Record_Glob.Record_Comp = Next_Record_Glob;
|
---|
138 | Record_Glob.Discr = Ident_1;
|
---|
139 | Record_Glob.Enum_Comp = Ident_3;
|
---|
140 | Record_Glob.Int_Comp = 40;
|
---|
141 | Record_Glob.String_Comp = "DHRYSTONE PROGRAM, SOME STRING";
|
---|
142 | String_Loc_1 = "DHRYSTONE PROGRAM, 1'ST STRING";
|
---|
143 |
|
---|
144 | for (int i = 0; i < 128; i++) {
|
---|
145 | Array_Glob_2[i] = new int[128];
|
---|
146 | }
|
---|
147 |
|
---|
148 | Stopwatch sw = new Stopwatch();
|
---|
149 | sw.Start();
|
---|
150 |
|
---|
151 | Run_Index = 1;
|
---|
152 | while (!stopBenchmark) {
|
---|
153 | Proc_5();
|
---|
154 | Proc_4();
|
---|
155 |
|
---|
156 | Int_Loc_1 = 2;
|
---|
157 | Int_Loc_2 = 3;
|
---|
158 |
|
---|
159 | String_Loc_2 = "DHRYSTONE PROGRAM, 2'ND STRING";
|
---|
160 |
|
---|
161 | Enum_Loc[0] = Ident_2;
|
---|
162 | Bool_Glob = !Func_2(String_Loc_1, String_Loc_2);
|
---|
163 |
|
---|
164 | while (Int_Loc_1 < Int_Loc_2) {
|
---|
165 | Int_Loc_3_Ref[0] = 5 * Int_Loc_1 - Int_Loc_2;
|
---|
166 | Proc_7(Int_Loc_1, Int_Loc_2, Int_Loc_3_Ref);
|
---|
167 | Int_Loc_1 += 1;
|
---|
168 | }
|
---|
169 |
|
---|
170 | Int_Loc_3 = Int_Loc_3_Ref[0];
|
---|
171 | Proc_8(Array_Glob_1, Array_Glob_2, Int_Loc_1, Int_Loc_3);
|
---|
172 | Proc_1(Record_Glob);
|
---|
173 |
|
---|
174 | for (Char_Index = 'A'; Char_Index <= Char_Glob_2; ++Char_Index) {
|
---|
175 | if (Enum_Loc[0] == Func_1(Char_Index, 'C'))
|
---|
176 | Proc_6(Ident_1, Enum_Loc);
|
---|
177 | }
|
---|
178 |
|
---|
179 | Int_Loc_3 = Int_Loc_2 * Int_Loc_1;
|
---|
180 | Int_Loc_2 = Int_Loc_3 / Int_Loc_1;
|
---|
181 | Int_Loc_2 = 7 * (Int_Loc_3 - Int_Loc_2) - Int_Loc_1;
|
---|
182 |
|
---|
183 | Int_Loc_1_Ref[0] = Int_Loc_1;
|
---|
184 | Proc_2(Int_Loc_1_Ref);
|
---|
185 | Int_Loc_1 = Int_Loc_1_Ref[0];
|
---|
186 |
|
---|
187 | if (cancellationToken.IsCancellationRequested) {
|
---|
188 | throw new OperationCanceledException(cancellationToken);
|
---|
189 | }
|
---|
190 |
|
---|
191 | if ((timeLimit == null) || (timeLimit.TotalMilliseconds == 0)) {
|
---|
192 | if (Run_Index > Default_Number_Of_Runs) {
|
---|
193 | stopBenchmark = true;
|
---|
194 | }
|
---|
195 | } else if (sw.Elapsed > timeLimit) {
|
---|
196 | stopBenchmark = true;
|
---|
197 | }
|
---|
198 |
|
---|
199 | Run_Index++;
|
---|
200 | }
|
---|
201 |
|
---|
202 | sw.Stop();
|
---|
203 | total_time = sw.ElapsedMilliseconds;
|
---|
204 |
|
---|
205 | results.Add(new Result("DIPS", new DoubleValue(Run_Index * 1000 / total_time)));
|
---|
206 |
|
---|
207 | }
|
---|
208 |
|
---|
209 | private int Func_1(char Char_Par_1_Val, char Char_Par_2_Val) {
|
---|
210 | char Char_Loc_1;
|
---|
211 | char Char_Loc_2;
|
---|
212 |
|
---|
213 | Char_Loc_1 = Char_Par_1_Val;
|
---|
214 | Char_Loc_2 = Char_Loc_1;
|
---|
215 | if (Char_Loc_2 != Char_Par_2_Val)
|
---|
216 | return Ident_1;
|
---|
217 | else
|
---|
218 | return Ident_2;
|
---|
219 | }
|
---|
220 |
|
---|
221 | private bool Func_2(string String_Par_1_Ref, string String_Par_2_Ref) {
|
---|
222 | int Int_Loc;
|
---|
223 | char Char_Loc = '\0';
|
---|
224 |
|
---|
225 | Int_Loc = 2;
|
---|
226 |
|
---|
227 | while (Int_Loc <= 2) {
|
---|
228 | if (Func_1(String_Par_1_Ref[Int_Loc], String_Par_2_Ref[Int_Loc + 1]) == Ident_1) {
|
---|
229 | Char_Loc = 'A';
|
---|
230 | Int_Loc += 1;
|
---|
231 | }
|
---|
232 | }
|
---|
233 | if (Char_Loc >= 'W' && Char_Loc < 'z')
|
---|
234 | Int_Loc = 7;
|
---|
235 | if (Char_Loc == 'X')
|
---|
236 | return true;
|
---|
237 | else {
|
---|
238 | if (String_Par_1_Ref.CompareTo(String_Par_2_Ref) > 0) {
|
---|
239 | Int_Loc += 7;
|
---|
240 | return true;
|
---|
241 | } else
|
---|
242 | return false;
|
---|
243 | }
|
---|
244 | }
|
---|
245 |
|
---|
246 | private bool Func_3(int Enum_Par_Val) {
|
---|
247 | int Enum_Loc;
|
---|
248 |
|
---|
249 | Enum_Loc = Enum_Par_Val;
|
---|
250 | if (Enum_Loc == Ident_3)
|
---|
251 | return true;
|
---|
252 | else
|
---|
253 | return false;
|
---|
254 | }
|
---|
255 |
|
---|
256 | private void Proc_1(Record_Type Pointer_Par_Val) {
|
---|
257 | Record_Type Next_Record = Pointer_Par_Val.Record_Comp;
|
---|
258 |
|
---|
259 | Pointer_Par_Val.Record_Comp = Record_Glob;
|
---|
260 |
|
---|
261 | Pointer_Par_Val.Int_Comp = 5;
|
---|
262 |
|
---|
263 | Next_Record.Int_Comp = Pointer_Par_Val.Int_Comp;
|
---|
264 | Next_Record.Record_Comp = Pointer_Par_Val.Record_Comp;
|
---|
265 | Proc_3(Next_Record.Record_Comp);
|
---|
266 |
|
---|
267 | int[] Int_Ref = new int[1];
|
---|
268 |
|
---|
269 | if (Next_Record.Discr == Ident_1) {
|
---|
270 | Next_Record.Int_Comp = 6;
|
---|
271 | Int_Ref[0] = Next_Record.Enum_Comp;
|
---|
272 | Proc_6(Pointer_Par_Val.Enum_Comp, Int_Ref);
|
---|
273 | Next_Record.Enum_Comp = Int_Ref[0];
|
---|
274 | Next_Record.Record_Comp = Record_Glob.Record_Comp;
|
---|
275 | Int_Ref[0] = Next_Record.Int_Comp;
|
---|
276 | Proc_7(Next_Record.Int_Comp, 10, Int_Ref);
|
---|
277 | Next_Record.Int_Comp = Int_Ref[0];
|
---|
278 | } else
|
---|
279 | Pointer_Par_Val = Pointer_Par_Val.Record_Comp;
|
---|
280 | }
|
---|
281 |
|
---|
282 | private void Proc_2(int[] Int_Par_Ref) {
|
---|
283 | int Int_Loc;
|
---|
284 | int Enum_Loc;
|
---|
285 |
|
---|
286 | Int_Loc = Int_Par_Ref[0] + 10;
|
---|
287 | Enum_Loc = 0;
|
---|
288 |
|
---|
289 | do
|
---|
290 | if (Char_Glob_1 == 'A') {
|
---|
291 | Int_Loc -= 1;
|
---|
292 | Int_Par_Ref[0] = Int_Loc - Int_Glob;
|
---|
293 | Enum_Loc = Ident_1;
|
---|
294 | }
|
---|
295 | while (Enum_Loc != Ident_1);
|
---|
296 | }
|
---|
297 |
|
---|
298 | private void Proc_3(Record_Type Pointer_Par_Ref) {
|
---|
299 | if (Record_Glob != null)
|
---|
300 | Pointer_Par_Ref = Record_Glob.Record_Comp;
|
---|
301 | else
|
---|
302 | Int_Glob = 100;
|
---|
303 |
|
---|
304 | int[] Int_Comp_Ref = new int[1];
|
---|
305 | Int_Comp_Ref[0] = Record_Glob.Int_Comp;
|
---|
306 | Proc_7(10, Int_Glob, Int_Comp_Ref);
|
---|
307 | Record_Glob.Int_Comp = Int_Comp_Ref[0];
|
---|
308 | }
|
---|
309 |
|
---|
310 | private void Proc_4() {
|
---|
311 | bool Bool_Loc;
|
---|
312 |
|
---|
313 | Bool_Loc = Char_Glob_1 == 'A';
|
---|
314 | Bool_Loc = Bool_Loc || Bool_Glob;
|
---|
315 | Char_Glob_2 = 'B';
|
---|
316 | }
|
---|
317 |
|
---|
318 | private void Proc_5() {
|
---|
319 | Char_Glob_1 = 'A';
|
---|
320 | Bool_Glob = false;
|
---|
321 | }
|
---|
322 |
|
---|
323 | private void Proc_6(int Enum_Par_Val, int[] Enum_Par_Ref) {
|
---|
324 |
|
---|
325 | Enum_Par_Ref[0] = Enum_Par_Val;
|
---|
326 |
|
---|
327 | if (!Func_3(Enum_Par_Val))
|
---|
328 | Enum_Par_Ref[0] = Ident_4;
|
---|
329 |
|
---|
330 | switch (Enum_Par_Val) {
|
---|
331 | case Ident_1:
|
---|
332 | Enum_Par_Ref[0] = Ident_1;
|
---|
333 | break;
|
---|
334 |
|
---|
335 | case Ident_2:
|
---|
336 | if (Int_Glob > 100)
|
---|
337 | Enum_Par_Ref[0] = Ident_1;
|
---|
338 | else
|
---|
339 | Enum_Par_Ref[0] = Ident_4;
|
---|
340 | break;
|
---|
341 |
|
---|
342 | case Ident_3:
|
---|
343 | Enum_Par_Ref[0] = Ident_2;
|
---|
344 | break;
|
---|
345 |
|
---|
346 | case Ident_4:
|
---|
347 | break;
|
---|
348 |
|
---|
349 | case Ident_5:
|
---|
350 | Enum_Par_Ref[0] = Ident_3;
|
---|
351 | break;
|
---|
352 | }
|
---|
353 | }
|
---|
354 |
|
---|
355 | private void Proc_7(int Int_Par_Val1, int Int_Par_Val2, int[] Int_Par_Ref) {
|
---|
356 | int Int_Loc;
|
---|
357 | Int_Loc = Int_Par_Val1 + 2;
|
---|
358 | Int_Par_Ref[0] = Int_Par_Val2 + Int_Loc;
|
---|
359 | }
|
---|
360 |
|
---|
361 | private void Proc_8(int[] Array_Par_1_Ref, int[][] Array_Par_2_Ref, int Int_Par_Val_1, int Int_Par_Val_2) {
|
---|
362 | int Int_Index;
|
---|
363 | int Int_Loc;
|
---|
364 |
|
---|
365 | Int_Loc = Int_Par_Val_1 + 5;
|
---|
366 | Array_Par_1_Ref[Int_Loc] = Int_Par_Val_2;
|
---|
367 | Array_Par_1_Ref[Int_Loc + 1] = Array_Par_1_Ref[Int_Loc];
|
---|
368 | Array_Par_1_Ref[Int_Loc + 30] = Int_Loc;
|
---|
369 |
|
---|
370 | for (Int_Index = Int_Loc; Int_Index <= Int_Loc + 1; ++Int_Index)
|
---|
371 | Array_Par_2_Ref[Int_Loc][Int_Index] = Int_Loc;
|
---|
372 | Array_Par_2_Ref[Int_Loc][Int_Loc - 1] += 1;
|
---|
373 | Array_Par_2_Ref[Int_Loc + 20][Int_Loc] = Array_Par_1_Ref[Int_Loc];
|
---|
374 | Int_Glob = 5;
|
---|
375 | }
|
---|
376 |
|
---|
377 | #endregion
|
---|
378 |
|
---|
379 | #region Private Class
|
---|
380 |
|
---|
381 | private class Record_Type {
|
---|
382 | public Record_Type Record_Comp;
|
---|
383 | public int Discr;
|
---|
384 | public int Enum_Comp;
|
---|
385 | public int Int_Comp;
|
---|
386 | public string String_Comp;
|
---|
387 | }
|
---|
388 |
|
---|
389 | #endregion
|
---|
390 |
|
---|
391 | #region Clone
|
---|
392 |
|
---|
393 | public IDeepCloneable Clone(Cloner cloner) {
|
---|
394 | return new DhrystoneBenchmark(this, cloner);
|
---|
395 | }
|
---|
396 |
|
---|
397 | public object Clone() {
|
---|
398 | return Clone(new Cloner());
|
---|
399 | }
|
---|
400 |
|
---|
401 | #endregion
|
---|
402 |
|
---|
403 | #region Events
|
---|
404 |
|
---|
405 | public event EventHandler ItemImageChanged;
|
---|
406 | protected virtual void OnItemImageChanged() {
|
---|
407 | EventHandler handler = ItemImageChanged;
|
---|
408 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
409 | }
|
---|
410 |
|
---|
411 | public event EventHandler ToStringChanged;
|
---|
412 | protected virtual void OnToStringChanged() {
|
---|
413 | EventHandler handler = ToStringChanged;
|
---|
414 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
415 | }
|
---|
416 |
|
---|
417 | #endregion
|
---|
418 |
|
---|
419 |
|
---|
420 | }
|
---|
421 | }
|
---|