Changeset 6948 for branches/Benchmarking/sources
- Timestamp:
- 11/04/11 13:13:17 (13 years ago)
- Location:
- branches/Benchmarking/sources
- Files:
-
- 4 added
- 3 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Benchmarking/sources/HeuristicLab.Algorithms.Benchmarks.Views/3.3/BenchmarkView.cs
r6934 r6948 26 26 namespace HeuristicLab.Algorithms.Benchmarks.Views { 27 27 [View("Benchmark View")] 28 [Content(typeof(Whetstone), true)] 29 [Content(typeof(Dhrystone), true)] 30 [Content(typeof(Linpack), true)] 28 [Content(typeof(Benchmark), true)] 31 29 public partial class BenchmarkView : AlgorithmView { 32 30 public BenchmarkView() { 33 31 InitializeComponent(); 34 32 tabControl.TabPages.Remove(this.problemTabPage); 35 tabControl.TabPages.Remove(this.parametersTabPage);36 33 } 37 34 } -
branches/Benchmarking/sources/HeuristicLab.Algorithms.Benchmarks/3.3/Benchmark.cs
r6934 r6948 31 31 using HeuristicLab.Data; 32 32 using HeuristicLab.Optimization; 33 using HeuristicLab.Parameters; 33 34 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 35 using HeuristicLab.PluginInfrastructure; 34 36 35 37 namespace HeuristicLab.Algorithms.Benchmarks { … … 37 39 /// A base class for benchmarks. 38 40 /// </summary> 39 [Item("Benchmark", "A base class for benchmarks.")] 41 [Item("Benchmark", "A wrapper for benchmark algorithms.")] 42 [Creatable("Benchmarks")] 40 43 [StorableClass] 41 public abstract class Benchmark : IAlgorithm { 42 44 public class Benchmark : IAlgorithm { 45 private Random random = new Random(); 46 47 [Storable] 43 48 private DateTime lastUpdateTime; 49 50 [Storable] 51 private IBenchmark benchmarkAlgorithm; 52 public IBenchmark BenchmarkAlgorithm { 53 get { return benchmarkAlgorithm; } 54 set { 55 if (value == null) throw new ArgumentNullException(); 56 benchmarkAlgorithm = value; 57 } 58 } 59 60 private CancellationTokenSource cancellationTokenSource; 44 61 45 62 [Storable] … … 202 219 } 203 220 221 #region Parameter Properties 222 223 public ConstrainedValueParameter<IBenchmark> BenchmarkAlgorithmParameter { 224 get { return (ConstrainedValueParameter<IBenchmark>)Parameters["BenchmarkAlgorithm"]; } 225 } 226 227 private ValueParameter<IntValue> ChunkSizeParameter { 228 get { return (ValueParameter<IntValue>)Parameters["ChunkSize"]; } 229 } 230 231 private ValueParameter<DoubleValue> TimeLimitParameter { 232 get { return (ValueParameter<DoubleValue>)Parameters["TimeLimit"]; } 233 } 234 235 #endregion 236 204 237 #region Constructors 205 238 206 p rotectedBenchmark() {239 public Benchmark() { 207 240 name = ItemName; 208 241 description = ItemDescription; … … 215 248 Runs = new RunCollection(); 216 249 results = new ResultCollection(); 250 CreateParameters(); 251 DiscoverBenchmarks(); 217 252 Prepare(); 218 253 } 219 254 220 p rotectedBenchmark(Benchmark original, Cloner cloner) {255 public Benchmark(Benchmark original, Cloner cloner) { 221 256 cloner.RegisterClonedObject(original, this); 222 257 name = original.name; … … 232 267 Initialize(); 233 268 234 results = new ResultCollection(); 269 results = cloner.Clone(original.results); 270 DiscoverBenchmarks(); 235 271 Prepare(); 236 272 } 237 273 238 274 #endregion 275 276 private void CreateParameters() { 277 Parameters.Add(new ValueParameter<IntValue>("ChunkSize", "The size (MB) of the chunk array that gets generated", new IntValue(0))); 278 Parameters.Add(new ValueParameter<DoubleValue>("TimeLimit", "The time limit (in minutes) for a benchmark run", new DoubleValue(0))); 279 } 280 281 private void DiscoverBenchmarks() { 282 var benchmarks = from t in ApplicationManager.Manager.GetTypes(typeof(IBenchmark)) 283 select t; 284 ItemSet<IBenchmark> values = new ItemSet<IBenchmark>(); 285 foreach (var benchmark in benchmarks) { 286 IBenchmark b = (IBenchmark)Activator.CreateInstance(benchmark); 287 values.Add(b); 288 } 289 string paramName = "BenchmarkAlgorithm"; 290 if (!Parameters.ContainsKey(paramName)) { 291 if (values.Count > 0) { 292 Parameters.Add(new ConstrainedValueParameter<IBenchmark>(paramName, values, values.First(a => a is IBenchmark))); 293 } else { 294 // throw exception? 295 Parameters.Add(new ConstrainedValueParameter<IBenchmark>(paramName, values)); 296 } 297 } 298 } 239 299 240 300 private void Initialize() { … … 264 324 if ((ExecutionState != ExecutionState.Started) && (ExecutionState != ExecutionState.Paused)) 265 325 throw new InvalidOperationException(string.Format("Stop not allowed in execution state \"{0}\".", ExecutionState)); 326 cancellationTokenSource.Cancel(); 266 327 } 267 328 268 329 public virtual void Start() { 269 varcancellationTokenSource = new CancellationTokenSource();330 cancellationTokenSource = new CancellationTokenSource(); 270 331 OnStarted(); 271 332 Task task = Task.Factory.StartNew(Run, cancellationTokenSource.Token, cancellationTokenSource.Token); … … 283 344 } 284 345 } 346 285 347 cancellationTokenSource.Dispose(); 286 348 cancellationTokenSource = null; … … 297 359 timer.Start(); 298 360 try { 299 RunBenchmark(); 361 BenchmarkAlgorithm = (IBenchmark)BenchmarkAlgorithmParameter.ActualValue; 362 int chunkSize = ((IntValue)ChunkSizeParameter.ActualValue).Value; 363 if (chunkSize > 0) { 364 BenchmarkAlgorithm.ChunkData = CreateDataChuck(chunkSize); 365 } 366 BenchmarkAlgorithm.TimeLimit = TimeSpan.FromMinutes(((DoubleValue)TimeLimitParameter.ActualValue).Value); 367 BenchmarkAlgorithm.Run(cancellationToken, results); 368 } 369 catch (OperationCanceledException) { 370 //Console.WriteLine(ex.ToString()); 300 371 } 301 372 finally { … … 304 375 ExecutionTime += DateTime.Now - lastUpdateTime; 305 376 } 306 307 cancellationToken.ThrowIfCancellationRequested(); 308 } 309 310 protected abstract void RunBenchmark(); 377 } 311 378 312 379 private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { … … 348 415 } 349 416 417 private byte[][] CreateDataChuck(int megaBytes) { 418 if (megaBytes <= 0) { 419 throw new ArgumentException("MegaBytes must be greater than zero", "megaBytes"); 420 } 421 byte[][] chunk = new byte[megaBytes][]; 422 for (int i = 0; i < chunk.Length; i++) { 423 chunk[i] = new byte[1024 * 1024]; 424 random.NextBytes(chunk[i]); 425 } 426 return chunk; 427 } 428 /* 429 private int[] CreateDataChuck(int megaBytes) { 430 if (megaBytes <= 0) { 431 throw new ArgumentException("MegaBytes must be greater than zero", "megaBytes"); 432 } 433 int size = (megaBytes * 1020 * 1024) / sizeof(int); 434 int[] data = new int[size]; 435 for (int i = 0; i < data.Length; i++) { 436 data[i] = random.Next(); 437 } 438 return data; 439 } 440 */ 441 350 442 #region Events 351 443 … … 464 556 #endregion 465 557 466 #region IDeepCloneable Members 467 468 public abstract IDeepCloneable Clone(Cloner cloner); 469 470 #endregion 471 472 #region ICloneable Members 558 #region Clone 559 560 public IDeepCloneable Clone(Cloner cloner) { 561 return new Benchmark(this, cloner); 562 } 473 563 474 564 public object Clone() { -
branches/Benchmarking/sources/HeuristicLab.Algorithms.Benchmarks/3.3/HeuristicLab.Algorithms.Benchmarks-3.3.csproj
r6934 r6948 51 51 <SubType>Code</SubType> 52 52 </Compile> 53 <Compile Include=" Whetstone.cs" />54 <Compile Include=" Dhrystone.cs" />55 <Compile Include="Linpack .cs" />53 <Compile Include="DhrystoneBenchmark.cs" /> 54 <Compile Include="IBenchmark.cs" /> 55 <Compile Include="LinpackBenchmark.cs" /> 56 56 <Compile Include="Plugin.cs" /> 57 57 <Compile Include="Properties\AssemblyInfo.cs" /> 58 <Compile Include="WhetstoneAlgorithm.cs" /> 58 59 </ItemGroup> 59 60 <ItemGroup>
Note: See TracChangeset
for help on using the changeset viewer.