Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Benchmarking/sources/HeuristicLab.Algorithms.Benchmarks/3.3/DhrystoneBenchmark.cs @ 6987

Last change on this file since 6987 was 6987, checked in by spimming, 12 years ago

#1659:

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