Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/30/11 02:38:12 (12 years ago)
Author:
swagner
Message:

Changes due to review of benchmark algorithms (#1659):

  • added base class Benchmark for benchmark implementations
  • implemented ToString in Benchmark base class
  • removed suffix Benchmark from class names of benchmark implementations
  • sealed benchmark implementations Linpack, Dhrystone and Whetstone
File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.Benchmarks/3.3/Whetstone.cs

    r7246 r7247  
    2222using System;
    2323using System.Diagnostics;
    24 using System.Drawing;
    2524using System.Threading;
    2625using HeuristicLab.Common;
     
    3130
    3231namespace HeuristicLab.Algorithms.Benchmarks {
    33   [Item("Whetstone Benchmark", "Whetstone performance benchmark algorithm.")]
     32  [Item("Whetstone", "Whetstone performance benchmark.")]
    3433  [StorableClass]
    35   public class WhetstoneBenchmark : IBenchmark {
    36     [Storable]
    37     private byte[][] chunk;
    38     public byte[][] ChunkData {
    39       get { return chunk; }
    40       set { chunk = value; }
    41     }
    42 
    43     [Storable]
    44     private TimeSpan timeLimit;
    45     public TimeSpan TimeLimit {
    46       get { return timeLimit; }
    47       set { timeLimit = value; }
    48     }
    49 
    50     private bool stopBenchmark;
    51 
    52     private CancellationToken cancellationToken;
    53 
    54     public string ItemName {
    55       get { return ItemAttribute.GetName(this.GetType()); }
    56     }
    57 
    58     public string ItemDescription {
    59       get { return ItemAttribute.GetDescription(this.GetType()); }
    60     }
    61 
    62     public Version ItemVersion {
    63       get { return ItemAttribute.GetVersion(this.GetType()); }
    64     }
    65 
    66     public static Image StaticItemImage {
    67       get { return HeuristicLab.Common.Resources.VSImageLibrary.Event; }
    68     }
    69     public Image ItemImage {
    70       get { return ItemAttribute.GetImage(this.GetType()); }
    71     }
    72 
    73     #region Benchmark Fields
    74 
     34  public sealed class Whetstone : Benchmark {
    7535    private long begin_time;
    7636    private long end_time;
     
    8444    private int i, j, k, l, n1, n2, n3, n4, n6, n7, n8, n9, n10, n11;
    8545
    86     #endregion
    87 
    88     #region Costructors
    89 
    9046    [StorableConstructor]
    91     public WhetstoneBenchmark(bool deserializing) { }
    92 
    93     public WhetstoneBenchmark() { }
    94 
    95     protected WhetstoneBenchmark(WhetstoneBenchmark original, Cloner cloner) {
    96       cloner.RegisterClonedObject(original, this);
    97     }
    98 
    99     #endregion
    100 
    101     #region Whetstone Benchmark
     47    private Whetstone(bool deserializing) : base(deserializing) { }
     48    private Whetstone(Whetstone original, Cloner cloner) : base(original, cloner) { }
     49    public Whetstone() { }
     50
     51    public override IDeepCloneable Clone(Cloner cloner) {
     52      return new Whetstone(this, cloner);
     53    }
     54
    10255    // implementation based on Java version: www.aicas.com/download/Whetstone.java
    103 
    104     public void Run(CancellationToken token, ResultCollection results) {
    105       cancellationToken = token;
    106       stopBenchmark = false;
     56    public override void Run(CancellationToken cancellationToken, ResultCollection results) {
     57      bool stopBenchmark = false;
    10758
    10859      ITERATIONS = 100; // ITERATIONS / 10 = Millions Whetstone instructions
     
    13283        }
    13384
    134         if ((timeLimit == null) || (timeLimit.TotalMilliseconds == 0)) {
     85        if ((TimeLimit == null) || (TimeLimit.TotalMilliseconds == 0)) {
    13586          if (runNumber > defaultNumberOfRuns) {
    13687            stopBenchmark = true;
    13788          }
    138         } else if (sw.Elapsed > timeLimit) {
     89        } else if (sw.Elapsed > TimeLimit) {
    13990          stopBenchmark = true;
    14091        }
     
    293244      e1[l] = e1[j];
    294245    }
    295 
    296     #endregion
    297 
    298     #region Clone
    299 
    300     public IDeepCloneable Clone(Cloner cloner) {
    301       return new WhetstoneBenchmark(this, cloner);
    302     }
    303 
    304     public object Clone() {
    305       return Clone(new Cloner());
    306     }
    307 
    308     #endregion
    309 
    310     #region Events
    311 
    312     public event EventHandler ItemImageChanged;
    313     protected virtual void OnItemImageChanged() {
    314       EventHandler handler = ItemImageChanged;
    315       if (handler != null) handler(this, EventArgs.Empty);
    316     }
    317 
    318     public event EventHandler ToStringChanged;
    319     protected virtual void OnToStringChanged() {
    320       EventHandler handler = ToStringChanged;
    321       if (handler != null) handler(this, EventArgs.Empty);
    322     }
    323 
    324     #endregion
    325246  }
    326247}
Note: See TracChangeset for help on using the changeset viewer.