Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Algorithms.Benchmarks/3.3/Dhrystone.cs @ 14128

Last change on this file since 14128 was 12012, checked in by ascheibe, 10 years ago

#2212 merged r12008, r12009, r12010 back into trunk

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