Changeset 6934 for branches/Benchmarking/sources/HeuristicLab.Algorithms.Benchmarks/3.3/Whetstone.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/Whetstone.cs
r6920 r6934 1 using System; 2 using System.Threading; 3 using System.Threading.Tasks; 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; 4 23 using HeuristicLab.Common; 5 24 using HeuristicLab.Core; … … 9 28 10 29 namespace HeuristicLab.Algorithms.Benchmarks { 11 [Item("Whetstone Algorithm", " A Whetstone benchmarkalgorithm.")]30 [Item("Whetstone Algorithm", "Whetstone benchmarking algorithm.")] 12 31 [Creatable("Benchmarks")] 13 32 [StorableClass] 14 public class Whetstone : Algorithm { 15 private DateTime lastUpdateTime; 16 17 [Storable] 18 private ResultCollection results; 33 public class Whetstone : Benchmark { 19 34 20 35 #region Benchmark Fields … … 22 37 private long begin_time; 23 38 private long end_time; 24 //private long total_time;25 39 26 40 private int ITERATIONS; … … 34 48 #endregion 35 49 36 #region Properties37 38 public override ResultCollection Results {39 get { return results; }40 }41 42 #endregion43 44 50 #region Costructors 45 51 46 52 public Whetstone() 47 53 : base() { 48 results = new ResultCollection(); 54 49 55 } 50 56 51 57 private Whetstone(Whetstone original, Cloner cloner) 52 58 : base(original, cloner) { 53 results = new ResultCollection(); 54 } 55 56 #endregion 59 60 } 61 62 #endregion 63 64 #region IDeepClonable Members 57 65 58 66 public override IDeepCloneable Clone(Cloner cloner) { … … 60 68 } 61 69 62 public override void Prepare() { 63 results.Clear(); 64 OnPrepared(); 65 } 66 67 public override void Start() { 68 var cancellationTokenSource = new CancellationTokenSource(); 69 OnStarted(); 70 Task task = Task.Factory.StartNew(Run, cancellationTokenSource.Token, cancellationTokenSource.Token); 71 task.ContinueWith(t => { 72 try { 73 t.Wait(); 74 } 75 catch (AggregateException ex) { 76 try { 77 ex.Flatten().Handle(x => x is OperationCanceledException); 78 } 79 catch (AggregateException remaining) { 80 if (remaining.InnerExceptions.Count == 1) OnExceptionOccurred(remaining.InnerExceptions[0]); 81 else OnExceptionOccurred(remaining); 82 } 83 } 84 cancellationTokenSource.Dispose(); 85 cancellationTokenSource = null; 86 OnStopped(); 87 }); 88 } 89 90 private void Run(object state) { 91 CancellationToken cancellationToken = (CancellationToken)state; 92 lastUpdateTime = DateTime.Now; 93 System.Timers.Timer timer = new System.Timers.Timer(250); 94 timer.AutoReset = true; 95 timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed); 96 timer.Start(); 97 try { 98 RunBenchmark(); 99 } 100 finally { 101 timer.Elapsed -= new System.Timers.ElapsedEventHandler(timer_Elapsed); 102 timer.Stop(); 103 ExecutionTime += DateTime.Now - lastUpdateTime; 104 } 105 106 cancellationToken.ThrowIfCancellationRequested(); 107 } 108 109 private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { 110 System.Timers.Timer timer = (System.Timers.Timer)sender; 111 timer.Enabled = false; 112 DateTime now = DateTime.Now; 113 ExecutionTime += now - lastUpdateTime; 114 lastUpdateTime = now; 115 timer.Enabled = true; 116 } 70 #endregion 117 71 118 72 #region Whetstone Benchmark 119 73 120 pr ivate void RunBenchmark() {74 protected override void RunBenchmark() { 121 75 ITERATIONS = 100; // ITERATIONS / 10 = Millions Whetstone instructions 122 76 … … 130 84 131 85 for (int runNumber = 1; runNumber <= numberOfRuns; runNumber++) { 132 //System.Console.WriteLine(runNumber + ". Test");133 86 elapsedTime = (float)(MainCalc() / 1000); 134 87 meanTime = meanTime + (elapsedTime * 1000 / numberOfCycles); … … 142 95 meanRating = meanRating / numberOfRuns; 143 96 intRating = (int)meanRating; 144 //System.Console.WriteLine("Number of Runs " + numberOfRuns); 145 //System.Console.WriteLine("Average time per cycle " + meanTime + " ms."); 146 //System.Console.WriteLine("Average Whetstone Rating " + intRating + " KWIPS"); 147 //Results.Add(new Result("KWIPS", new IntValue(intRating))); 97 148 98 Results.Add(new Result("MWIPS", new IntValue(intRating / 1000))); 149 99 } … … 264 214 265 215 end_time = DateTime.Now.Ticks / 10000; // get ms 266 //System.Console.WriteLine(" (time for " + numberOfCycles + " cycles): " + (end_time - begin_time) + " millisec.");267 216 268 217 return (end_time - begin_time);
Note: See TracChangeset
for help on using the changeset viewer.