Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7247


Ignore:
Timestamp:
12/30/11 02:38:12 (13 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
Location:
trunk/sources/HeuristicLab.Algorithms.Benchmarks/3.3
Files:
1 added
1 edited
3 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.Benchmarks/3.3/Dhrystone.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("Dhrystone Benchmark", "Dhrystone performance benchmark algorithm.")]
     32  [Item("Dhrystone", "Dhrystone performance benchmark.")]
    3433  [StorableClass]
    35   public class DhrystoneBenchmark : IBenchmark {
    36     private bool stopBenchmark;
    37     private CancellationToken cancellationToken;
    38 
    39     public string ItemName {
    40       get { return ItemAttribute.GetName(this.GetType()); }
    41     }
    42     public string ItemDescription {
    43       get { return ItemAttribute.GetDescription(this.GetType()); }
    44     }
    45     public Version ItemVersion {
    46       get { return ItemAttribute.GetVersion(this.GetType()); }
    47     }
    48     public static Image StaticItemImage {
    49       get { return HeuristicLab.Common.Resources.VSImageLibrary.Event; }
    50     }
    51     public Image ItemImage {
    52       get { return ItemAttribute.GetImage(this.GetType()); }
    53     }
    54 
    55     [Storable]
    56     private byte[][] chunk;
    57     public byte[][] ChunkData {
    58       get { return chunk; }
    59       set { chunk = value; }
    60     }
    61 
    62     [Storable]
    63     private TimeSpan timeLimit;
    64     public TimeSpan TimeLimit {
    65       get { return timeLimit; }
    66       set { timeLimit = value; }
    67     }
    68 
    69 
    70     #region Benchmark Fields
    71 
     34  public sealed class Dhrystone : Benchmark {
    7235    private const int Ident_1 = 0;
    7336    private const int Ident_2 = 1;
     
    9356    private long Default_Number_Of_Runs = 10000000;
    9457
    95     #endregion
    96 
    97     #region Costructors
    98 
    9958    [StorableConstructor]
    100     public DhrystoneBenchmark(bool deserializing) { }
    101 
    102     public DhrystoneBenchmark() { }
    103 
    104     protected DhrystoneBenchmark(DhrystoneBenchmark original, Cloner cloner) {
    105       cloner.RegisterClonedObject(original, this);
    106     }
    107 
    108     #endregion
    109 
    110     #region Benchmark Methods
     59    private Dhrystone(bool deserializing) : base(deserializing) { }
     60    private Dhrystone(Dhrystone original, Cloner cloner) : base(original, cloner) { }
     61    public Dhrystone() { }
     62
     63    public override IDeepCloneable Clone(Cloner cloner) {
     64      return new Dhrystone(this, cloner);
     65    }
     66
     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;
     73    }
     74
    11175    // implementation based on Java version: http://www.okayan.jp/DhrystoneApplet/dhry_src.jar
    112 
    113     public void Run(CancellationToken token, ResultCollection results) {
    114       cancellationToken = token;
    115       stopBenchmark = false;
     76    public override void Run(CancellationToken cancellationToken, ResultCollection results) {
     77      bool stopBenchmark = false;
    11678
    11779      int Int_Loc_1;
     
    189151        }
    190152
    191         if ((timeLimit == null) || (timeLimit.TotalMilliseconds == 0)) {
     153        if ((TimeLimit == null) || (TimeLimit.TotalMilliseconds == 0)) {
    192154          if (Run_Index > Default_Number_Of_Runs) {
    193155            stopBenchmark = true;
    194156          }
    195         } else if (sw.Elapsed > timeLimit) {
     157        } else if (sw.Elapsed > TimeLimit) {
    196158          stopBenchmark = true;
    197159        }
     
    374336      Int_Glob = 5;
    375337    }
    376 
    377     #endregion
    378 
    379     #region Private Class
    380 
    381     private class Record_Type {
    382       public Record_Type Record_Comp;
    383       public int Discr;
    384       public int Enum_Comp;
    385       public int Int_Comp;
    386       public string String_Comp;
    387     }
    388 
    389     #endregion
    390 
    391     #region Clone
    392 
    393     public IDeepCloneable Clone(Cloner cloner) {
    394       return new DhrystoneBenchmark(this, cloner);
    395     }
    396 
    397     public object Clone() {
    398       return Clone(new Cloner());
    399     }
    400 
    401     #endregion
    402 
    403     #region Events
    404 
    405     public event EventHandler ItemImageChanged;
    406     protected virtual void OnItemImageChanged() {
    407       EventHandler handler = ItemImageChanged;
    408       if (handler != null) handler(this, EventArgs.Empty);
    409     }
    410 
    411     public event EventHandler ToStringChanged;
    412     protected virtual void OnToStringChanged() {
    413       EventHandler handler = ToStringChanged;
    414       if (handler != null) handler(this, EventArgs.Empty);
    415     }
    416 
    417     #endregion
    418 
    419 
    420338  }
    421339}
  • trunk/sources/HeuristicLab.Algorithms.Benchmarks/3.3/HeuristicLab.Algorithms.Benchmarks-3.3.csproj

    r7246 r7247  
    8989  </ItemGroup>
    9090  <ItemGroup>
     91    <Compile Include="Benchmark.cs" />
    9192    <Compile Include="BenchmarkAlgorithm.cs" />
    92     <Compile Include="DhrystoneBenchmark.cs" />
     93    <Compile Include="Dhrystone.cs" />
    9394    <Compile Include="IBenchmark.cs" />
    94     <Compile Include="LinpackBenchmark.cs" />
     95    <Compile Include="Linpack.cs" />
    9596    <Compile Include="Plugin.cs" />
    9697    <Compile Include="Properties\AssemblyInfo.cs" />
    97     <Compile Include="WhetstoneBenchmark.cs" />
     98    <Compile Include="Whetstone.cs" />
    9899  </ItemGroup>
    99100  <ItemGroup>
  • 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}
  • 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.