Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/15/11 13:34:38 (13 years ago)
Author:
mkommend
Message:

#1418: Finally added results from the grammar refactoring.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/ProbabilisticTreeCreaterTest.cs

    r5445 r5686  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Diagnostics;
    2425using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2526using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;
     
    3031  [TestClass]
    3132  public class ProbabilisticTreeCreaterTest {
    32     private const int POPULATION_SIZE = 1000;
     33    private const int POPULATION_SIZE = 10000;
    3334    private const int MAX_TREE_SIZE = 100;
    3435    private const int MAX_TREE_HEIGHT = 10;
     
    5354      var grammar = Grammars.CreateSimpleArithmeticGrammar();
    5455      var random = new MersenneTwister(31415);
     56      var stopwatch = new Stopwatch();
     57      stopwatch.Start();
    5558      for (int i = 0; i < POPULATION_SIZE; i++) {
    5659        randomTrees.Add(ProbabilisticTreeCreator.Create(random, grammar, MAX_TREE_SIZE, MAX_TREE_HEIGHT, 0, 0));
    5760      }
     61      stopwatch.Stop();
    5862
    5963      foreach (var tree in randomTrees) {
    6064        Util.IsValid(tree);
    6165      }
     66      double msPerRandomTreeCreation = stopwatch.ElapsedMilliseconds / (double)POPULATION_SIZE;
     67
    6268      Console.WriteLine("ProbabilisticTreeCreator: " + Environment.NewLine +
     69        msPerRandomTreeCreation + " ms per random tree (~" + Math.Round(1000.0 / (msPerRandomTreeCreation)) + "random trees / s)" + Environment.NewLine +
    6370        Util.GetSizeDistributionString(randomTrees, 105, 5) + Environment.NewLine +
    6471        Util.GetFunctionDistributionString(randomTrees) + Environment.NewLine +
     
    6673        Util.GetTerminalDistributionString(randomTrees) + Environment.NewLine
    6774        );
     75      Assert.IsTrue(Math.Round(1000.0 / (msPerRandomTreeCreation)) > 2000); // must achieve more than 2000 random trees / s
    6876    }
    6977
     
    7482      var grammar = Grammars.CreateArithmeticAndAdfGrammar();
    7583      var random = new MersenneTwister(31415);
     84      var stopwatch = new Stopwatch();
     85      stopwatch.Start();
    7686      for (int i = 0; i < POPULATION_SIZE; i++) {
    77         var tree = ProbabilisticTreeCreator.Create(random, grammar, MAX_TREE_SIZE, MAX_TREE_HEIGHT, 3, 3);
     87        randomTrees.Add(ProbabilisticTreeCreator.Create(random, grammar, MAX_TREE_SIZE, MAX_TREE_HEIGHT, 3, 3));
     88      }
     89      stopwatch.Stop();
     90      foreach (var tree in randomTrees)
    7891        Util.IsValid(tree);
    79         randomTrees.Add(tree);
    80       }
     92
     93      double msPerRandomTreeCreation = stopwatch.ElapsedMilliseconds / (double)POPULATION_SIZE;
     94
    8195      Console.WriteLine("ProbabilisticTreeCreator: " + Environment.NewLine +
     96        msPerRandomTreeCreation + " ms per random tree (~" + Math.Round(1000.0 / (msPerRandomTreeCreation)) + "random trees / s)" + Environment.NewLine +
    8297        Util.GetSizeDistributionString(randomTrees, 105, 5) + Environment.NewLine +
    8398        Util.GetFunctionDistributionString(randomTrees) + Environment.NewLine +
     
    85100        Util.GetTerminalDistributionString(randomTrees) + Environment.NewLine
    86101        );
     102
     103      Assert.IsTrue(Math.Round(1000.0 / (msPerRandomTreeCreation)) > 2000); // must achieve more than 2000 random trees / s
    87104    }
    88105  }
Note: See TracChangeset for help on using the changeset viewer.