Changeset 6934 for branches/Benchmarking/sources/HeuristicLab.Algorithms.Benchmarks/3.3/Dhrystone.cs
- Timestamp:
- 10/18/11 15:08:14 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Benchmarking/sources/HeuristicLab.Algorithms.Benchmarks/3.3/Dhrystone.cs
r6920 r6934 1 using System; 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; 2 23 using System.Diagnostics; 3 using System.Threading;4 using System.Threading.Tasks;5 24 using HeuristicLab.Common; 6 25 using HeuristicLab.Core; … … 10 29 11 30 namespace HeuristicLab.Algorithms.Benchmarks { 12 [Item("Dhrystone Algorithm", " A Dhrystone benchmarkalgorithm.")]31 [Item("Dhrystone Algorithm", "Dhrystone benchmarking algorithm.")] 13 32 [Creatable("Benchmarks")] 14 33 [StorableClass] 15 public class Dhrystone : Algorithm { 16 private DateTime lastUpdateTime; 17 18 [Storable] 19 private ResultCollection results; 34 public class Dhrystone : Benchmark { 20 35 21 36 #region Benchmark Fields … … 46 61 #endregion 47 62 48 #region Properties49 50 public override ResultCollection Results {51 get { return results; }52 }53 54 #endregion55 56 63 #region Costructors 57 64 58 65 public Dhrystone() 59 66 : base() { 60 results = new ResultCollection(); 67 61 68 } 62 69 63 70 private Dhrystone(Dhrystone original, Cloner cloner) 64 71 : base(original, cloner) { 65 results = new ResultCollection(); 66 } 67 68 #endregion 72 73 } 74 75 #endregion 76 77 #region IDeepClonable Members 69 78 70 79 public override IDeepCloneable Clone(Cloner cloner) { … … 72 81 } 73 82 74 public override void Prepare() { 75 results.Clear(); 76 OnPrepared(); 77 } 78 79 public override void Start() { 80 var cancellationTokenSource = new CancellationTokenSource(); 81 OnStarted(); 82 Task task = Task.Factory.StartNew(Run, cancellationTokenSource.Token, cancellationTokenSource.Token); 83 task.ContinueWith(t => { 84 try { 85 t.Wait(); 86 } 87 catch (AggregateException ex) { 88 try { 89 ex.Flatten().Handle(x => x is OperationCanceledException); 90 } 91 catch (AggregateException remaining) { 92 if (remaining.InnerExceptions.Count == 1) OnExceptionOccurred(remaining.InnerExceptions[0]); 93 else OnExceptionOccurred(remaining); 94 } 95 } 96 cancellationTokenSource.Dispose(); 97 cancellationTokenSource = null; 98 OnStopped(); 99 }); 100 } 101 102 private void Run(object state) { 103 CancellationToken cancellationToken = (CancellationToken)state; 104 lastUpdateTime = DateTime.Now; 105 System.Timers.Timer timer = new System.Timers.Timer(250); 106 timer.AutoReset = true; 107 timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed); 108 timer.Start(); 109 try { 110 RunBenchmark(); 111 } 112 finally { 113 timer.Elapsed -= new System.Timers.ElapsedEventHandler(timer_Elapsed); 114 timer.Stop(); 115 ExecutionTime += DateTime.Now - lastUpdateTime; 116 } 117 118 cancellationToken.ThrowIfCancellationRequested(); 119 } 120 121 private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { 122 System.Timers.Timer timer = (System.Timers.Timer)sender; 123 timer.Enabled = false; 124 DateTime now = DateTime.Now; 125 ExecutionTime += now - lastUpdateTime; 126 lastUpdateTime = now; 127 timer.Enabled = true; 128 } 129 130 #region Dhrystone Benchmark 131 132 private void RunBenchmark() { 83 #endregion 84 85 #region Benchmark Methods 86 87 protected override void RunBenchmark() { 133 88 int Int_Loc_1; 134 89 int Int_Loc_2; … … 162 117 } 163 118 164 //System.Console.WriteLine("Execution start, " + Number_Of_Runs + " runs through Dhrystone");165 119 Stopwatch sw = new Stopwatch(); 166 120 sw.Start(); … … 205 159 sw.Stop(); 206 160 total_time = sw.ElapsedMilliseconds; 207 //System.Console.WriteLine("total time: {0} ms", total_time);208 //System.Console.WriteLine("Result: " + Number_Of_Runs * 1000 / total_time + " dhrystone/ms.");209 161 210 162 Results.Add(new Result("DIPS", new DoubleValue(Number_Of_Runs * 1000 / total_time))); … … 389 341 public int Int_Comp; 390 342 public string String_Comp; 391 /*392 public int Enum_Comp_2;393 public string String_Comp_2;394 public char Char_Comp_1;395 public char Char_Comp_2;396 */397 343 } 398 344
Note: See TracChangeset
for help on using the changeset viewer.