Exemple #1
0
        static void _Perf(FA nfa, string test)
        {
            var       t  = F.UnicodeUtility.ToUtf32(test);
            var       sw = DateTimeUtility.HasPreciseTime ? null : new Stopwatch();
            DateTime  utcStart;
            DateTime  utcEnd;
            TimeSpan  elapsed = TimeSpan.Zero;
            const int ITER    = 100;

            ConsoleUtility.WriteProgressBar(0, false);
            for (var i = 0; i < ITER; ++i)
            {
                if (0 == ((i + 1) % 10))
                {
                    ConsoleUtility.WriteProgressBar(i, true);
                }
                var sb   = new StringBuilder();
                var more = true;
                var e    = t.GetEnumerator();
                while (more)
                {
                    sb.Clear();
                    if (!DateTimeUtility.HasPreciseTime)
                    {
                        sw.Start();
                        nfa.Lex(e, sb, out more);
                        sw.Stop();
                        elapsed += sw.Elapsed;
                    }
                    else
                    {
                        utcStart = DateTimeUtility.UtcNow;
                        nfa.Lex(e, sb, out more);
                        utcEnd   = DateTimeUtility.UtcNow;
                        elapsed += (utcEnd - utcStart);
                    }
                }
            }
            ConsoleUtility.EraseProgressBar();
            Console.WriteLine("Lexed in " + elapsed.TotalMilliseconds / (float)ITER + " msec");
        }
Exemple #2
0
        static void _Perf(int[][] prog, string test)
        {
            var       sw = DateTimeUtility.HasPreciseTime?null:new Stopwatch();
            DateTime  utcStart;
            DateTime  utcEnd;
            TimeSpan  elapsed = TimeSpan.Zero;
            const int ITER    = 100;

            ConsoleUtility.WriteProgressBar(0, false);
            for (var i = 0; i < ITER; ++i)
            {
                if (0 == ((i + 1) % 10))
                {
                    ConsoleUtility.WriteProgressBar(i, true);
                }
                var lc = LexContext.Create(test);
                while (LexContext.EndOfInput != lc.Current)
                {
                    lc.ClearCapture();
                    if (!DateTimeUtility.HasPreciseTime)
                    {
                        sw.Start();
                        Lex.Run(prog, lc);
                        sw.Stop();
                        elapsed += sw.Elapsed;
                    }
                    else
                    {
                        utcStart = DateTimeUtility.UtcNow;
                        Lex.Run(prog, lc);
                        utcEnd   = DateTimeUtility.UtcNow;
                        elapsed += (utcEnd - utcStart);
                    }
                }
            }
            ConsoleUtility.EraseProgressBar();
            Console.WriteLine("Lexed in " + elapsed.TotalMilliseconds / (float)ITER + " msec");
        }