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/Linpack.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("Linpack Benchmark", "Linpack performance benchmark algorithm.")]
     32  [Item("Linpack", "Linpack performance benchmark.")]
    3433  [StorableClass]
    35   public class LinpackBenchmark : 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 Linpack : Benchmark {
    7535    private const int DEFAULT_PSIZE = 1500;
    7636
     
    8141    private double total = 0.0;
    8242
     43    private CancellationToken cancellationToken;
    8344    private Stopwatch sw = new Stopwatch();
    8445
    85     #endregion
    86 
    87     #region Costructors
    88 
    8946    [StorableConstructor]
    90     public LinpackBenchmark(bool deserializing) { }
    91 
    92     public LinpackBenchmark() { }
    93 
    94     public LinpackBenchmark(LinpackBenchmark original, Cloner cloner) {
    95       cloner.RegisterClonedObject(original, this);
    96     }
    97 
    98     #endregion
    99 
    100     #region Linpack Benchmark
     47    private Linpack(bool deserializing) : base(deserializing) { }
     48    private Linpack(Linpack original, Cloner cloner) : base(original, cloner) { }
     49    public Linpack() { }
     50
     51    public override IDeepCloneable Clone(Cloner cloner) {
     52      return new Linpack(this, cloner);
     53    }
     54
    10155    // implementation based on Java version: http://www.netlib.org/benchmark/linpackjava/
    102 
    103     public void Run(CancellationToken token, ResultCollection results) {
     56    public override void Run(CancellationToken token, ResultCollection results) {
    10457      cancellationToken = token;
    105       stopBenchmark = false;
     58      bool stopBenchmark = false;
    10659      TimeSpan executionTime = new TimeSpan();
    10760      bool resultAchieved = false;
     
    197150
    198151        executionTime += sw.Elapsed;
    199         if ((timeLimit == null) || (timeLimit.TotalMilliseconds == 0))
     152        if ((TimeLimit == null) || (TimeLimit.TotalMilliseconds == 0))
    200153          stopBenchmark = true;
    201         else if (executionTime > timeLimit)
     154        else if (executionTime > TimeLimit)
    202155          stopBenchmark = true;
    203156      } while (!stopBenchmark);
     
    534487      }
    535488    }
    536 
    537     #endregion
    538 
    539     #region Clone
    540 
    541     public IDeepCloneable Clone(Cloner cloner) {
    542       return new LinpackBenchmark(this, cloner);
    543     }
    544 
    545     public object Clone() {
    546       return Clone(new Cloner());
    547     }
    548 
    549     #endregion
    550 
    551     #region Events
    552 
    553     public event EventHandler ItemImageChanged;
    554     protected virtual void OnItemImageChanged() {
    555       EventHandler handler = ItemImageChanged;
    556       if (handler != null) handler(this, EventArgs.Empty);
    557     }
    558 
    559     public event EventHandler ToStringChanged;
    560     protected virtual void OnToStringChanged() {
    561       EventHandler handler = ToStringChanged;
    562       if (handler != null) handler(this, EventArgs.Empty);
    563     }
    564 
    565     #endregion
    566489  }
    567490}
Note: See TracChangeset for help on using the changeset viewer.