#region License Information /* HeuristicLab * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Diagnostics; using System.Threading; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Optimization; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Algorithms.Benchmarks { [Item("Sleep", "Sleep performance benchmark.")] [StorableClass] public sealed class Sleep : Benchmark { [StorableConstructor] private Sleep(bool deserializing) : base(deserializing) { } private Sleep(Sleep original, Cloner cloner) : base(original, cloner) { } public Sleep() { } public override IDeepCloneable Clone(Cloner cloner) { return new Sleep(this, cloner); } public override void Run(CancellationToken cancellationToken, ResultCollection results) { bool stopBenchmark = false; int defaultNumberOfRuns = 10; long runNumber = 1; Stopwatch sw = new Stopwatch(); sw.Start(); while (!stopBenchmark) { MainCalc(); if (cancellationToken.IsCancellationRequested) { throw new OperationCanceledException(cancellationToken); } if ((TimeLimit == null) || (TimeLimit.TotalMilliseconds == 0)) { if (runNumber > defaultNumberOfRuns) { stopBenchmark = true; } } else if (sw.Elapsed > TimeLimit) { stopBenchmark = true; } runNumber++; } sw.Stop(); results.Add(new Result("MWIPS", new IntValue(42))); } private void MainCalc() { Thread.Sleep(10000); } } }