Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveStatistics/sources/HeuristicLab.Algorithms.Benchmarks/3.3/Sleep.cs @ 12188

Last change on this file since 12188 was 9372, checked in by pfleck, 12 years ago

#2030 Added Sleep-BenchmarkAlgorithm.

File size: 2.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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
22using System;
23using System.Diagnostics;
24using System.Threading;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Optimization;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Algorithms.Benchmarks {
32  [Item("Sleep", "Sleep performance benchmark.")]
33  [StorableClass]
34  public sealed class Sleep : Benchmark {
35    [StorableConstructor]
36    private Sleep(bool deserializing) : base(deserializing) { }
37    private Sleep(Sleep original, Cloner cloner) : base(original, cloner) { }
38    public Sleep() { }
39
40    public override IDeepCloneable Clone(Cloner cloner) {
41      return new Sleep(this, cloner);
42    }
43
44    public override void Run(CancellationToken cancellationToken, ResultCollection results) {
45      bool stopBenchmark = false;
46
47      int defaultNumberOfRuns = 10;
48      long runNumber = 1;
49
50      Stopwatch sw = new Stopwatch();
51      sw.Start();
52
53      while (!stopBenchmark) {
54
55        MainCalc();
56
57        if (cancellationToken.IsCancellationRequested) {
58          throw new OperationCanceledException(cancellationToken);
59        }
60
61        if ((TimeLimit == null) || (TimeLimit.TotalMilliseconds == 0)) {
62          if (runNumber > defaultNumberOfRuns) {
63            stopBenchmark = true;
64          }
65        } else if (sw.Elapsed > TimeLimit) {
66          stopBenchmark = true;
67        }
68
69        runNumber++;
70      }
71      sw.Stop();
72
73      results.Add(new Result("MWIPS", new IntValue(42)));
74    }
75
76    private void MainCalc() {
77
78      Thread.Sleep(10000);
79
80    }
81  }
82}
83
Note: See TracBrowser for help on using the repository browser.