Example #1
0
        private static string GenerateTestSourceCode(IBenchmark bench)
        {
            StringWriter sw = new StringWriter();

            sw.WriteLine("using System;");

            sw.WriteLine(bench.Header);

            sw.WriteLine("public class TheBenchmark {");
            sw.WriteLine("static TheBenchmark() {");
            sw.WriteLine("}");
            sw.WriteLine(bench.CreateSource("logger1", "nosuchlogger"));
            sw.WriteLine(bench.CreateSource("logger2", "null1"));
            sw.WriteLine(bench.CreateSource("logger3", "null2"));
            sw.WriteLine(bench.CreateSource("logger4", "file1"));
            sw.WriteLine(bench.CreateSource("logger5", "file3"));
            sw.WriteLine(bench.CreateSource("logger6", "file2"));

            sw.WriteLine("public static void Init() {");
            //sw.WriteLine("Console.WriteLine(\"Init\");");
            sw.WriteLine(bench.Init);
            sw.WriteLine("} // Init()");
            sw.WriteLine("public static void Flush() {");
            //sw.WriteLine("Console.WriteLine(\"Flushing\");");
            sw.WriteLine(bench.Flush);
            //sw.WriteLine("Console.WriteLine(\"Flushed\");");
            sw.WriteLine("} // Flush()");
            sw.WriteLine("public static void DoNothing() {");
            sw.WriteLine("} // DoNothing()");
            sw.WriteLine("public static void NoLogging() {");
            sw.WriteLine(bench.WriteUnformatted("logger1", "Debug", "Lorem Ipsum"));
            sw.WriteLine(bench.WriteUnformatted("logger1", "Info", "Lorem Ipsum"));
            sw.WriteLine(bench.WriteUnformatted("logger1", "Warn", "Lorem Ipsum"));
            sw.WriteLine(bench.WriteUnformatted("logger1", "Error", "Lorem Ipsum"));
            sw.WriteLine(bench.WriteUnformatted("logger1", "Fatal", "Lorem Ipsum"));
            sw.WriteLine("}");
            sw.WriteLine("public static void NoLoggingWithFormatting1() {");
            sw.WriteLine(bench.WriteFormatted("logger1", "Debug", "Lorem Ipsum", "1"));
            sw.WriteLine(bench.WriteFormatted("logger1", "Info", "Lorem Ipsum", "2"));
            sw.WriteLine(bench.WriteFormatted("logger1", "Warn", "Lorem Ipsum", "3"));
            sw.WriteLine(bench.WriteFormatted("logger1", "Error", "Lorem Ipsum", "4"));
            sw.WriteLine(bench.WriteFormatted("logger1", "Fatal", "Lorem Ipsum", "5"));
            sw.WriteLine("}");
            sw.WriteLine("public static void NoLoggingWithFormatting2() {");
            sw.WriteLine(bench.WriteFormatted("logger1", "Debug", "Lorem Ipsum", "1,2"));
            sw.WriteLine(bench.WriteFormatted("logger1", "Info", "Lorem Ipsum", "2,3"));
            sw.WriteLine(bench.WriteFormatted("logger1", "Warn", "Lorem Ipsum", "3,4"));
            sw.WriteLine(bench.WriteFormatted("logger1", "Error", "Lorem Ipsum", "4,5"));
            sw.WriteLine(bench.WriteFormatted("logger1", "Fatal", "Lorem Ipsum", "5,6"));
            sw.WriteLine("}");
            sw.WriteLine("public static void NoLoggingWithFormatting3() {");
            sw.WriteLine(bench.WriteFormatted("logger1", "Debug", "Lorem Ipsum", "true,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger1", "Info", "Lorem Ipsum", "1,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger1", "Warn", "Lorem Ipsum", "false,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger1", "Error", "Lorem Ipsum", "1,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger1", "Fatal", "Lorem Ipsum", "true,2,\"test\""));
            sw.WriteLine("}");
            sw.WriteLine("public static void GuardedNoLogging() {");
            sw.WriteLine(bench.GuardedWrite("logger1", "Debug", "Lorem Ipsum", "true,2,\"test\""));
            sw.WriteLine(bench.GuardedWrite("logger1", "Info", "Lorem Ipsum", "1,2,\"test\""));
            sw.WriteLine(bench.GuardedWrite("logger1", "Warn", "Lorem Ipsum", "false,2,\"test\""));
            sw.WriteLine(bench.GuardedWrite("logger1", "Error", "Lorem Ipsum", "1,2,\"test\""));
            sw.WriteLine(bench.GuardedWrite("logger1", "Fatal", "Lorem Ipsum", "true,2,\"test\""));
            sw.WriteLine("}");
            sw.WriteLine("public static void NullLoggingWithoutFormatting() {");
            sw.WriteLine(bench.WriteUnformatted("logger2", "Debug", "Lorem Ipsum"));
            sw.WriteLine(bench.WriteUnformatted("logger2", "Info", "Lorem Ipsum"));
            sw.WriteLine(bench.WriteUnformatted("logger2", "Warn", "Lorem Ipsum"));
            sw.WriteLine(bench.WriteUnformatted("logger2", "Error", "Lorem Ipsum"));
            sw.WriteLine(bench.WriteUnformatted("logger2", "Fatal", "Lorem Ipsum"));
            sw.WriteLine("}");
            sw.WriteLine("public static void NullLoggingWithFormatting1() {");
            sw.WriteLine(bench.WriteFormatted("logger2", "Debug", "Lorem Ipsum", "1"));
            sw.WriteLine(bench.WriteFormatted("logger2", "Info", "Lorem Ipsum", "2"));
            sw.WriteLine(bench.WriteFormatted("logger2", "Warn", "Lorem Ipsum", "3"));
            sw.WriteLine(bench.WriteFormatted("logger2", "Error", "Lorem Ipsum", "4"));
            sw.WriteLine(bench.WriteFormatted("logger2", "Fatal", "Lorem Ipsum", "5"));
            sw.WriteLine("}");
            sw.WriteLine("public static void NullLoggingWithFormatting3() {");
            sw.WriteLine(bench.WriteFormatted("logger2", "Debug", "Lorem Ipsum", "true,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger2", "Info", "Lorem Ipsum", "1,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger2", "Warn", "Lorem Ipsum", "false,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger2", "Error", "Lorem Ipsum", "1,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger2", "Fatal", "Lorem Ipsum", "true,2,\"test\""));
            sw.WriteLine("}");
            sw.WriteLine("public static void NoRenderingLoggingWithoutFormatting() {");
            sw.WriteLine(bench.WriteUnformatted("logger3", "Debug", "Lorem Ipsum"));
            sw.WriteLine(bench.WriteUnformatted("logger3", "Info", "Lorem Ipsum"));
            sw.WriteLine(bench.WriteUnformatted("logger3", "Warn", "Lorem Ipsum"));
            sw.WriteLine(bench.WriteUnformatted("logger3", "Error", "Lorem Ipsum"));
            sw.WriteLine(bench.WriteUnformatted("logger3", "Fatal", "Lorem Ipsum"));
            sw.WriteLine("}");
            sw.WriteLine("public static void NoRenderingLoggingWithFormatting1() {");
            sw.WriteLine(bench.WriteFormatted("logger3", "Debug", "Lorem Ipsum", "1"));
            sw.WriteLine(bench.WriteFormatted("logger3", "Info", "Lorem Ipsum", "2"));
            sw.WriteLine(bench.WriteFormatted("logger3", "Warn", "Lorem Ipsum", "3"));
            sw.WriteLine(bench.WriteFormatted("logger3", "Error", "Lorem Ipsum", "4"));
            sw.WriteLine(bench.WriteFormatted("logger3", "Fatal", "Lorem Ipsum", "5"));
            sw.WriteLine("}");
            sw.WriteLine("public static void NoRenderingLoggingWithFormatting3() {");
            sw.WriteLine(bench.WriteFormatted("logger3", "Debug", "Lorem Ipsum", "true,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger3", "Info", "Lorem Ipsum", "1,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger3", "Warn", "Lorem Ipsum", "false,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger3", "Error", "Lorem Ipsum", "1,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger3", "Fatal", "Lorem Ipsum", "true,2,\"test\""));
            sw.WriteLine("}");
            sw.WriteLine("public static void SimpleFile() {");
            sw.WriteLine(bench.WriteFormatted("logger4", "Debug", "Lorem Ipsum", "true,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger4", "Info", "Lorem Ipsum", "1,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger4", "Warn", "Lorem Ipsum", "false,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger4", "Error", "Lorem Ipsum", "1,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger4", "Fatal", "Lorem Ipsum", "true,2,\"test\""));
            sw.WriteLine("}");
            sw.WriteLine("public static void BufferedFile() {");
            sw.WriteLine(bench.WriteFormatted("logger5", "Debug", "Lorem Ipsum", "true,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger5", "Info", "Lorem Ipsum", "1,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger5", "Warn", "Lorem Ipsum", "false,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger5", "Error", "Lorem Ipsum", "1,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger5", "Fatal", "Lorem Ipsum", "true,2,\"test\""));
            sw.WriteLine("}");
            sw.WriteLine("public static void AsyncFile() {");
            sw.WriteLine(bench.WriteFormatted("logger6", "Debug", "Lorem Ipsum", "true,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger6", "Info", "Lorem Ipsum", "1,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger6", "Warn", "Lorem Ipsum", "false,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger6", "Error", "Lorem Ipsum", "1,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger6", "Fatal", "Lorem Ipsum", "true,2,\"test\""));
            sw.WriteLine("}");
            sw.WriteLine("}");
            return(sw.ToString());
        }
Example #2
0
        private static string GenerateTestSourceCode(IBenchmark bench)
        {
            StringWriter sw = new StringWriter();

            sw.WriteLine("using System;");

            sw.WriteLine(bench.Header);

            sw.WriteLine("public class TheBenchmark {");
            sw.WriteLine("static TheBenchmark() {");
            sw.WriteLine("}");
            sw.WriteLine(bench.CreateSource("logger1", "nosuchlogger"));
            sw.WriteLine(bench.CreateSource("logger2", "null1"));
            sw.WriteLine(bench.CreateSource("logger3", "null2"));
            sw.WriteLine(bench.CreateSource("logger4", "file1"));
            sw.WriteLine(bench.CreateSource("logger5", "file3"));
            sw.WriteLine(bench.CreateSource("logger6", "file2"));

            sw.WriteLine("public static void Init() {");
            //sw.WriteLine("Console.WriteLine(\"Init\");");
            sw.WriteLine(bench.Init);
            sw.WriteLine("} // Init()");
            sw.WriteLine("public static void Flush() {");
            //sw.WriteLine("Console.WriteLine(\"Flushing\");");
            sw.WriteLine(bench.Flush);
            //sw.WriteLine("Console.WriteLine(\"Flushed\");");
            sw.WriteLine("} // Flush()");
            sw.WriteLine("public static void DoNothing() {");
            sw.WriteLine("} // DoNothing()");
            sw.WriteLine("public static void NoLogging() {");
            sw.WriteLine(bench.WriteUnformatted("logger1", "Debug", "Lorem Ipsum"));
            sw.WriteLine(bench.WriteUnformatted("logger1", "Info", "Lorem Ipsum"));
            sw.WriteLine(bench.WriteUnformatted("logger1", "Warn", "Lorem Ipsum"));
            sw.WriteLine(bench.WriteUnformatted("logger1", "Error", "Lorem Ipsum"));
            sw.WriteLine(bench.WriteUnformatted("logger1", "Fatal", "Lorem Ipsum"));
            sw.WriteLine("}");
            sw.WriteLine("public static void NoLoggingWithFormatting1() {");
            sw.WriteLine(bench.WriteFormatted("logger1", "Debug", "Lorem Ipsum", "1"));
            sw.WriteLine(bench.WriteFormatted("logger1", "Info", "Lorem Ipsum", "2"));
            sw.WriteLine(bench.WriteFormatted("logger1", "Warn", "Lorem Ipsum", "3"));
            sw.WriteLine(bench.WriteFormatted("logger1", "Error", "Lorem Ipsum", "4"));
            sw.WriteLine(bench.WriteFormatted("logger1", "Fatal", "Lorem Ipsum", "5"));
            sw.WriteLine("}");
            sw.WriteLine("public static void NoLoggingWithFormatting2() {");
            sw.WriteLine(bench.WriteFormatted("logger1", "Debug", "Lorem Ipsum", "1,2"));
            sw.WriteLine(bench.WriteFormatted("logger1", "Info", "Lorem Ipsum", "2,3"));
            sw.WriteLine(bench.WriteFormatted("logger1", "Warn", "Lorem Ipsum", "3,4"));
            sw.WriteLine(bench.WriteFormatted("logger1", "Error", "Lorem Ipsum", "4,5"));
            sw.WriteLine(bench.WriteFormatted("logger1", "Fatal", "Lorem Ipsum", "5,6"));
            sw.WriteLine("}");
            sw.WriteLine("public static void NoLoggingWithFormatting3() {");
            sw.WriteLine(bench.WriteFormatted("logger1", "Debug", "Lorem Ipsum", "true,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger1", "Info", "Lorem Ipsum", "1,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger1", "Warn", "Lorem Ipsum", "false,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger1", "Error", "Lorem Ipsum", "1,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger1", "Fatal", "Lorem Ipsum", "true,2,\"test\""));
            sw.WriteLine("}");
            sw.WriteLine("public static void GuardedNoLogging() {");
            sw.WriteLine(bench.GuardedWrite("logger1", "Debug", "Lorem Ipsum", "true,2,\"test\""));
            sw.WriteLine(bench.GuardedWrite("logger1", "Info", "Lorem Ipsum", "1,2,\"test\""));
            sw.WriteLine(bench.GuardedWrite("logger1", "Warn", "Lorem Ipsum", "false,2,\"test\""));
            sw.WriteLine(bench.GuardedWrite("logger1", "Error", "Lorem Ipsum", "1,2,\"test\""));
            sw.WriteLine(bench.GuardedWrite("logger1", "Fatal", "Lorem Ipsum", "true,2,\"test\""));
            sw.WriteLine("}");
            sw.WriteLine("public static void NullLoggingWithoutFormatting() {");
            sw.WriteLine(bench.WriteUnformatted("logger2", "Debug", "Lorem Ipsum"));
            sw.WriteLine(bench.WriteUnformatted("logger2", "Info", "Lorem Ipsum"));
            sw.WriteLine(bench.WriteUnformatted("logger2", "Warn", "Lorem Ipsum"));
            sw.WriteLine(bench.WriteUnformatted("logger2", "Error", "Lorem Ipsum"));
            sw.WriteLine(bench.WriteUnformatted("logger2", "Fatal", "Lorem Ipsum"));
            sw.WriteLine("}");
            sw.WriteLine("public static void NullLoggingWithFormatting1() {");
            sw.WriteLine(bench.WriteFormatted("logger2", "Debug", "Lorem Ipsum", "1"));
            sw.WriteLine(bench.WriteFormatted("logger2", "Info", "Lorem Ipsum", "2"));
            sw.WriteLine(bench.WriteFormatted("logger2", "Warn", "Lorem Ipsum", "3"));
            sw.WriteLine(bench.WriteFormatted("logger2", "Error", "Lorem Ipsum", "4"));
            sw.WriteLine(bench.WriteFormatted("logger2", "Fatal", "Lorem Ipsum", "5"));
            sw.WriteLine("}");
            sw.WriteLine("public static void NullLoggingWithFormatting3() {");
            sw.WriteLine(bench.WriteFormatted("logger2", "Debug", "Lorem Ipsum", "true,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger2", "Info", "Lorem Ipsum", "1,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger2", "Warn", "Lorem Ipsum", "false,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger2", "Error", "Lorem Ipsum", "1,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger2", "Fatal", "Lorem Ipsum", "true,2,\"test\""));
            sw.WriteLine("}");
            sw.WriteLine("public static void NoRenderingLoggingWithoutFormatting() {");
            sw.WriteLine(bench.WriteUnformatted("logger3", "Debug", "Lorem Ipsum"));
            sw.WriteLine(bench.WriteUnformatted("logger3", "Info", "Lorem Ipsum"));
            sw.WriteLine(bench.WriteUnformatted("logger3", "Warn", "Lorem Ipsum"));
            sw.WriteLine(bench.WriteUnformatted("logger3", "Error", "Lorem Ipsum"));
            sw.WriteLine(bench.WriteUnformatted("logger3", "Fatal", "Lorem Ipsum"));
            sw.WriteLine("}");
            sw.WriteLine("public static void NoRenderingLoggingWithFormatting1() {");
            sw.WriteLine(bench.WriteFormatted("logger3", "Debug", "Lorem Ipsum", "1"));
            sw.WriteLine(bench.WriteFormatted("logger3", "Info", "Lorem Ipsum", "2"));
            sw.WriteLine(bench.WriteFormatted("logger3", "Warn", "Lorem Ipsum", "3"));
            sw.WriteLine(bench.WriteFormatted("logger3", "Error", "Lorem Ipsum", "4"));
            sw.WriteLine(bench.WriteFormatted("logger3", "Fatal", "Lorem Ipsum", "5"));
            sw.WriteLine("}");
            sw.WriteLine("public static void NoRenderingLoggingWithFormatting3() {");
            sw.WriteLine(bench.WriteFormatted("logger3", "Debug", "Lorem Ipsum", "true,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger3", "Info", "Lorem Ipsum", "1,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger3", "Warn", "Lorem Ipsum", "false,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger3", "Error", "Lorem Ipsum", "1,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger3", "Fatal", "Lorem Ipsum", "true,2,\"test\""));
            sw.WriteLine("}");
            sw.WriteLine("public static void SimpleFile() {");
            sw.WriteLine(bench.WriteFormatted("logger4", "Debug", "Lorem Ipsum", "true,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger4", "Info", "Lorem Ipsum", "1,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger4", "Warn", "Lorem Ipsum", "false,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger4", "Error", "Lorem Ipsum", "1,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger4", "Fatal", "Lorem Ipsum", "true,2,\"test\""));
            sw.WriteLine("}");
            sw.WriteLine("public static void BufferedFile() {");
            sw.WriteLine(bench.WriteFormatted("logger5", "Debug", "Lorem Ipsum", "true,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger5", "Info", "Lorem Ipsum", "1,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger5", "Warn", "Lorem Ipsum", "false,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger5", "Error", "Lorem Ipsum", "1,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger5", "Fatal", "Lorem Ipsum", "true,2,\"test\""));
            sw.WriteLine("}");
            sw.WriteLine("public static void AsyncFile() {");
            sw.WriteLine(bench.WriteFormatted("logger6", "Debug", "Lorem Ipsum", "true,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger6", "Info", "Lorem Ipsum", "1,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger6", "Warn", "Lorem Ipsum", "false,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger6", "Error", "Lorem Ipsum", "1,2,\"test\""));
            sw.WriteLine(bench.WriteFormatted("logger6", "Fatal", "Lorem Ipsum", "true,2,\"test\""));
            sw.WriteLine("}");
            sw.WriteLine("}");
            return sw.ToString();
        }