Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1772_HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking.Tests/QueryMatchPerformanceTest.cs @ 17874

Last change on this file since 17874 was 12979, checked in by bburlacu, 9 years ago

#1772:

  • added parameters to the SchemaCreator for calculating things in parallel
  • added parallel code to the SchemaEvaluator
  • implemented quality calculation and saving of estimated values in the scope in the UpdateEstimatedValuesOperator
  • small refactoring of QueryMatch (added some useful methods and made NodeInfo internal)
  • updated query match unit test
File size: 2.1 KB
Line 
1using System;
2using System.Diagnostics;
3using System.Linq;
4using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
5using HeuristicLab.Problems.DataAnalysis.Symbolic;
6using HeuristicLab.Random;
7using Microsoft.VisualStudio.TestTools.UnitTesting;
8
9namespace HeuristicLab.EvolutionTracking.Tests {
10  [TestClass]
11  public class QueryMatchPerformanceTest {
12    private const int MaxDepth = 12;
13    private const int MaxLength = 50;
14    private const int N = 50000;
15    private const int Repetitions = 5;
16
17    [TestMethod]
18    public void TestQueryMatchPerformance() {
19      var grammar = new TypeCoherentExpressionGrammar();
20      grammar.ConfigureAsDefaultRegressionGrammar();
21      var creator = new ProbabilisticTreeCreator();
22      var random = new MersenneTwister();
23
24      var trees = Enumerable.Range(0, N).Select(x => creator.CreateTree(random, grammar, MaxLength, MaxDepth)).ToList();
25      var comparer = new SymbolicExpressionTreeNodeEqualityComparer {
26        MatchConstantValues = false,
27        MatchVariableWeights = false,
28        MatchVariableNames = true
29      };
30      var qm = new QueryMatch(comparer) { MatchParents = true };
31      // warmup
32      int count = trees.Skip(1).Count(x => qm.Match(x, trees[0]));
33
34      var sw = new Stopwatch();
35      sw.Start();
36      for (int i = 0; i < Repetitions; ++i)
37        count = trees.Skip(1).Count(x => x.Length >= trees[0].Length && qm.Match(x, trees[0]));
38      sw.Stop();
39
40      Console.WriteLine("Count: " + count);
41      Console.WriteLine("Query matches per second: " + (N - 1) / (sw.ElapsedMilliseconds / 1000.0) * Repetitions);
42      Console.WriteLine("Total time: " + sw.ElapsedMilliseconds / 1000.0 + "s");
43
44      sw.Restart();
45      for (int i = 0; i < Repetitions; ++i)
46        count = qm.GetMatchingTrees(trees.Skip(1), trees[0]).Count();
47      sw.Stop();
48
49      Console.WriteLine("Count: " + count);
50      Console.WriteLine("Optimized query matches per second: " + (N - 1) / (sw.ElapsedMilliseconds / 1000.0) * Repetitions);
51      Console.WriteLine("Total time: " + sw.ElapsedMilliseconds / 1000.0 + "s");
52    }
53  }
54}
Note: See TracBrowser for help on using the repository browser.