Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP.Cli/Program.cs @ 14392

Last change on this file since 14392 was 14392, checked in by pkimmesw, 8 years ago

#2665 Full Push 3.0 instruction set and tests; Added first benchmark test (count odds) for random walk tests;

File size: 2.4 KB
Line 
1using System;
2using System.Diagnostics;
3using System.Linq;
4using System.Threading.Tasks;
5using HeuristicLab.Algorithms.PushGP.Generators;
6using HeuristicLab.Algorithms.PushGP.Interpreter;
7
8namespace HeuristicLab.Algorithms.PushGP.Cli
9{
10    class Program
11    {
12        static void Main(string[] args)
13        {
14            Stepwise().Wait();
15            //PerformanceTestInterpreter();
16            //PerformanceTestCodeGenerator();
17
18            Console.WriteLine("\nPress any key to continue...");
19            Console.ReadKey();
20        }
21
22        static async Task Stepwise()
23        {
24            var interpreter = new PushGPInterpreter();
25
26            interpreter.InterpretAsync("( 0 2 CODE.QUOTE ( 1 INTEGER.+ 0 3 CODE.QUOTE ( 1 INTEGER.+ INTEGER.* ) CODE.DO*RANGE INTEGER.+ ) CODE.DO*RANGE )", true).Wait();
27
28            while (!interpreter.IsCompleted)
29            {
30                Console.Clear();
31                interpreter.PrintStacks();
32                interpreter.Step();
33
34                var input = Console.ReadKey();
35                if (input.Key == ConsoleKey.Escape)
36                {
37                    break;
38                }
39                else if (input.Key == ConsoleKey.Spacebar)
40                {
41                    await interpreter.ResumeAsync();
42                }
43            }
44
45            Console.Clear();
46            interpreter.PrintStacks();
47        }
48
49        static void PerformanceTestInterpreter()
50        {
51            var program = PushGPInterpreter.Encode("( 5 INTEGER.DUP INTEGER.+ )");
52            var interpreter = new PushGPInterpreter();
53            var sw = new Stopwatch();
54
55            sw.Start();
56            for (var i = 0; i < 20000000; i++)
57            {
58                interpreter.Interpret(program);
59                interpreter.Clear();
60            }
61            sw.Stop();
62
63            Console.WriteLine(sw.Elapsed);
64        }
65
66        static void PerformanceTestCodeGenerator()
67        {
68            var sw = new Stopwatch();
69
70            var interpreter = new PushGPInterpreter();
71            var generator = new CodeGenerator(interpreter);
72
73            sw.Start();
74            var expressions = generator.RandomCode(3000000);
75            sw.Stop();
76
77            Console.WriteLine(string.Format("Generated {0} in {1}", expressions.Count(), sw.Elapsed));
78        }
79    }
80}
Note: See TracBrowser for help on using the repository browser.