Esempio n. 1
0
        /// <summary>
        /// Runs a parse IR test (parsing the emitted the IR).
        /// </summary>
        /// <param name="interpreter"> The interpreter to emit from then read. </param>
        /// <param name="iterations"> How many times to run. </param>
        /// <param name="throwOut"> Print out average of results. </param>
        /// <param name="withComments"> Emit then read with comments? </param>
        private static void RunReadEmitTest(Interpreter interpreter, int iterations, bool throwOut, bool withComments)
        {
            Log.HandleLogs = true;
            Stopwatch     stopwatch = new Stopwatch();
            long          total     = 0;
            StringBuilder builder   = new StringBuilder();

            using (IRWriter writer = new IRWriter(builder)) {
                writer.Emit(interpreter, withComments);

                for (int i = 0; i < iterations; i++)
                {
                    stopwatch.Restart();
                    //.GetInterpreterFromText(builder.ToString(), Parser.ReadMode.IR);
                    stopwatch.Stop();
                    if (throwOut == false)
                    {
                        total += stopwatch.ElapsedMilliseconds;
                    }
                }
            }

            if (throwOut == false)
            {
                Log.HandleLogs = true;
                Log.Info($"<READ EMIT {(withComments ? "WITH COMMENTS" : "WITHOUT COMMENTS")} TEST> Took average of {(total / iterations)}ms to complete.  Did {iterations} times");
                Log.HandleLogs = true;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Runs an emit test (emitting the IR).
        /// </summary>
        /// <param name="interpreter"> The interpreter to emit from. </param>
        /// <param name="iterations"> How many times to run. </param>
        /// <param name="throwOut"> Print out average of results. </param>
        /// <param name="withComments"> Emit with comments? </param>
        private static void RunEmitTest(Interpreter interpreter, int iterations, bool throwOut, bool withComments)
        {
            Log.HandleLogs = true;
            Stopwatch stopwatch = new Stopwatch();
            long      total     = 0;

            for (int i = 0; i < iterations; i++)
            {
                StringBuilder builder = new StringBuilder();
                using (IRWriter writer = new IRWriter(builder)) {
                    stopwatch.Restart();
                    writer.Emit(interpreter, withComments);
                    stopwatch.Stop();

                    if (throwOut == false)
                    {
                        total += 1000 * stopwatch.ElapsedTicks;
                    }
                }
            }

            if (throwOut == false)
            {
                Log.HandleLogs = true;
                Log.Info($"<EMIT {(withComments ? "WITH COMMENTS" : "WITHOUT COMMENTS")} TEST> Took average of {((total / (double)Stopwatch.Frequency) / iterations)}ms to complete.  Did {iterations} times");
                Log.HandleLogs = true;
            }
        }