Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Benchmarking/sources/HeuristicLab.Algorithms.Benchmarks/3.3/Dhrystone.cs @ 6934

Last change on this file since 6934 was 6934, checked in by ascheibe, 12 years ago

on behalf of spimming:
#1659

  • implemented abstract base class for benchmarking algorithms
  • added License information
  • corrected plugin dependencies
  • corrected descriptions
File size: 9.1 KB
Line 
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 HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Optimization;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Algorithms.Benchmarks {
31  [Item("Dhrystone Algorithm", "Dhrystone benchmarking algorithm.")]
32  [Creatable("Benchmarks")]
33  [StorableClass]
34  public class Dhrystone : Benchmark {
35
36    #region Benchmark Fields
37
38    private const int Ident_1 = 0;
39    private const int Ident_2 = 1;
40    private const int Ident_3 = 2;
41    private const int Ident_4 = 3;
42    private const int Ident_5 = 4;
43
44    private Record_Type Record_Glob;
45    private Record_Type Next_Record_Glob;
46
47    private int Int_Glob;
48    private Boolean Bool_Glob;
49
50    private char Char_Glob_1;
51    private char Char_Glob_2;
52
53    private int[] Array_Glob_1 = new int[128];
54    private int[][] Array_Glob_2 = new int[128][];
55
56    private Record_Type First_Record = new Record_Type();
57    private Record_Type Second_Record = new Record_Type();
58
59    private long Number_Of_Runs = 10000000;
60
61    #endregion
62
63    #region Costructors
64
65    public Dhrystone()
66      : base() {
67
68    }
69
70    private Dhrystone(Dhrystone original, Cloner cloner)
71      : base(original, cloner) {
72
73    }
74
75    #endregion
76
77    #region IDeepClonable Members
78
79    public override IDeepCloneable Clone(Cloner cloner) {
80      return new Dhrystone(this, cloner);
81    }
82
83    #endregion
84
85    #region Benchmark Methods
86
87    protected override void RunBenchmark() {
88      int Int_Loc_1;
89      int Int_Loc_2;
90      int Int_Loc_3;
91
92      int[] Int_Loc_1_Ref = new int[1];
93      int[] Int_Loc_3_Ref = new int[1];
94
95      char Char_Index;
96      int[] Enum_Loc = new int[1];
97
98      string String_Loc_1;
99      string String_Loc_2;
100
101      long total_time;
102
103      int Run_Index;
104
105      Next_Record_Glob = Second_Record;
106      Record_Glob = First_Record;
107
108      Record_Glob.Record_Comp = Next_Record_Glob;
109      Record_Glob.Discr = Ident_1;
110      Record_Glob.Enum_Comp = Ident_3;
111      Record_Glob.Int_Comp = 40;
112      Record_Glob.String_Comp = "DHRYSTONE PROGRAM, SOME STRING";
113      String_Loc_1 = "DHRYSTONE PROGRAM, 1'ST STRING";
114
115      for (int i = 0; i < 128; i++) {
116        Array_Glob_2[i] = new int[128];
117      }
118
119      Stopwatch sw = new Stopwatch();
120      sw.Start();
121
122
123      for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index) {
124        Proc_5();
125        Proc_4();
126
127        Int_Loc_1 = 2;
128        Int_Loc_2 = 3;
129
130        String_Loc_2 = "DHRYSTONE PROGRAM, 2'ND STRING";
131
132        Enum_Loc[0] = Ident_2;
133        Bool_Glob = !Func_2(String_Loc_1, String_Loc_2);
134
135        while (Int_Loc_1 < Int_Loc_2) {
136          Int_Loc_3_Ref[0] = 5 * Int_Loc_1 - Int_Loc_2;
137          Proc_7(Int_Loc_1, Int_Loc_2, Int_Loc_3_Ref);
138          Int_Loc_1 += 1;
139        }
140
141        Int_Loc_3 = Int_Loc_3_Ref[0];
142        Proc_8(Array_Glob_1, Array_Glob_2, Int_Loc_1, Int_Loc_3);
143        Proc_1(Record_Glob);
144
145        for (Char_Index = 'A'; Char_Index <= Char_Glob_2; ++Char_Index) {
146          if (Enum_Loc[0] == Func_1(Char_Index, 'C'))
147            Proc_6(Ident_1, Enum_Loc);
148        }
149
150        Int_Loc_3 = Int_Loc_2 * Int_Loc_1;
151        Int_Loc_2 = Int_Loc_3 / Int_Loc_1;
152        Int_Loc_2 = 7 * (Int_Loc_3 - Int_Loc_2) - Int_Loc_1;
153
154        Int_Loc_1_Ref[0] = Int_Loc_1;
155        Proc_2(Int_Loc_1_Ref);
156        Int_Loc_1 = Int_Loc_1_Ref[0];
157      }
158
159      sw.Stop();
160      total_time = sw.ElapsedMilliseconds;
161
162      Results.Add(new Result("DIPS", new DoubleValue(Number_Of_Runs * 1000 / total_time)));
163    }
164
165    private int Func_1(char Char_Par_1_Val, char Char_Par_2_Val) {
166      char Char_Loc_1;
167      char Char_Loc_2;
168
169      Char_Loc_1 = Char_Par_1_Val;
170      Char_Loc_2 = Char_Loc_1;
171      if (Char_Loc_2 != Char_Par_2_Val)
172        return Ident_1;
173      else
174        return Ident_2;
175    }
176
177    private bool Func_2(string String_Par_1_Ref, string String_Par_2_Ref) {
178      int Int_Loc;
179      char Char_Loc = '\0';
180
181      Int_Loc = 2;
182
183      while (Int_Loc <= 2) {
184        if (Func_1(String_Par_1_Ref[Int_Loc], String_Par_2_Ref[Int_Loc + 1]) == Ident_1) {
185          Char_Loc = 'A';
186          Int_Loc += 1;
187        }
188      }
189      if (Char_Loc >= 'W' && Char_Loc < 'z')
190        Int_Loc = 7;
191      if (Char_Loc == 'X')
192        return true;
193      else {
194        if (String_Par_1_Ref.CompareTo(String_Par_2_Ref) > 0) {
195          Int_Loc += 7;
196          return true;
197        } else
198          return false;
199      }
200    }
201
202    private bool Func_3(int Enum_Par_Val) {
203      int Enum_Loc;
204
205      Enum_Loc = Enum_Par_Val;
206      if (Enum_Loc == Ident_3)
207        return true;
208      else
209        return false;
210    }
211
212    private void Proc_1(Record_Type Pointer_Par_Val) {
213      Record_Type Next_Record = Pointer_Par_Val.Record_Comp;
214
215      Pointer_Par_Val.Record_Comp = Record_Glob;
216
217      Pointer_Par_Val.Int_Comp = 5;
218
219      Next_Record.Int_Comp = Pointer_Par_Val.Int_Comp;
220      Next_Record.Record_Comp = Pointer_Par_Val.Record_Comp;
221      Proc_3(Next_Record.Record_Comp);
222
223      int[] Int_Ref = new int[1];
224
225      if (Next_Record.Discr == Ident_1) {
226        Next_Record.Int_Comp = 6;
227        Int_Ref[0] = Next_Record.Enum_Comp;
228        Proc_6(Pointer_Par_Val.Enum_Comp, Int_Ref);
229        Next_Record.Enum_Comp = Int_Ref[0];
230        Next_Record.Record_Comp = Record_Glob.Record_Comp;
231        Int_Ref[0] = Next_Record.Int_Comp;
232        Proc_7(Next_Record.Int_Comp, 10, Int_Ref);
233        Next_Record.Int_Comp = Int_Ref[0];
234      } else
235        Pointer_Par_Val = Pointer_Par_Val.Record_Comp;
236    }
237
238    private void Proc_2(int[] Int_Par_Ref) {
239      int Int_Loc;
240      int Enum_Loc;
241
242      Int_Loc = Int_Par_Ref[0] + 10;
243      Enum_Loc = 0;
244
245      do
246        if (Char_Glob_1 == 'A') {
247          Int_Loc -= 1;
248          Int_Par_Ref[0] = Int_Loc - Int_Glob;
249          Enum_Loc = Ident_1;
250        }
251      while (Enum_Loc != Ident_1);
252    }
253
254    private void Proc_3(Record_Type Pointer_Par_Ref) {
255      if (Record_Glob != null)
256        Pointer_Par_Ref = Record_Glob.Record_Comp;
257      else
258        Int_Glob = 100;
259
260      int[] Int_Comp_Ref = new int[1];
261      Int_Comp_Ref[0] = Record_Glob.Int_Comp;
262      Proc_7(10, Int_Glob, Int_Comp_Ref);
263      Record_Glob.Int_Comp = Int_Comp_Ref[0];
264    }
265
266    private void Proc_4() {
267      bool Bool_Loc;
268
269      Bool_Loc = Char_Glob_1 == 'A';
270      Bool_Loc = Bool_Loc || Bool_Glob;
271      Char_Glob_2 = 'B';
272    }
273
274    private void Proc_5() {
275      Char_Glob_1 = 'A';
276      Bool_Glob = false;
277    }
278
279    private void Proc_6(int Enum_Par_Val, int[] Enum_Par_Ref) {
280
281      Enum_Par_Ref[0] = Enum_Par_Val;
282
283      if (!Func_3(Enum_Par_Val))
284        Enum_Par_Ref[0] = Ident_4;
285
286      switch (Enum_Par_Val) {
287        case Ident_1:
288          Enum_Par_Ref[0] = Ident_1;
289          break;
290
291        case Ident_2:
292          if (Int_Glob > 100)
293            Enum_Par_Ref[0] = Ident_1;
294          else
295            Enum_Par_Ref[0] = Ident_4;
296          break;
297
298        case Ident_3:
299          Enum_Par_Ref[0] = Ident_2;
300          break;
301
302        case Ident_4:
303          break;
304
305        case Ident_5:
306          Enum_Par_Ref[0] = Ident_3;
307          break;
308      }
309    }
310
311    private void Proc_7(int Int_Par_Val1, int Int_Par_Val2, int[] Int_Par_Ref) {
312      int Int_Loc;
313      Int_Loc = Int_Par_Val1 + 2;
314      Int_Par_Ref[0] = Int_Par_Val2 + Int_Loc;
315    }
316
317    private void Proc_8(int[] Array_Par_1_Ref, int[][] Array_Par_2_Ref, int Int_Par_Val_1, int Int_Par_Val_2) {
318      int Int_Index;
319      int Int_Loc;
320
321      Int_Loc = Int_Par_Val_1 + 5;
322      Array_Par_1_Ref[Int_Loc] = Int_Par_Val_2;
323      Array_Par_1_Ref[Int_Loc + 1] = Array_Par_1_Ref[Int_Loc];
324      Array_Par_1_Ref[Int_Loc + 30] = Int_Loc;
325
326      for (Int_Index = Int_Loc; Int_Index <= Int_Loc + 1; ++Int_Index)
327        Array_Par_2_Ref[Int_Loc][Int_Index] = Int_Loc;
328      Array_Par_2_Ref[Int_Loc][Int_Loc - 1] += 1;
329      Array_Par_2_Ref[Int_Loc + 20][Int_Loc] = Array_Par_1_Ref[Int_Loc];
330      Int_Glob = 5;
331    }
332
333    #endregion
334
335    #region Private Class
336
337    private class Record_Type {
338      public Record_Type Record_Comp;
339      public int Discr;
340      public int Enum_Comp;
341      public int Int_Comp;
342      public string String_Comp;
343    }
344
345    #endregion
346  }
347}
Note: See TracBrowser for help on using the repository browser.