Пример #1
0
        public static void PrintStatisticsTable(string inputFileName, JsonExecutionTimes text, JsonExecutionTimes newtonsoft, JsonExecutionTimes binary)
        {
            // Until we merge the text table just do something hacky
            Console.WriteLine("Input File: " + inputFileName);

            Console.WriteLine(TextTable.TopLine);
            Console.WriteLine(TextTable.Header);
            Console.WriteLine(TextTable.MiddleLine);
            Console.WriteLine(TextTable.GetRow(
                                  "Text",
                                  text.ReadTime.TotalMilliseconds.ToString("0.00"),
                                  text.WriteTime.TotalMilliseconds.ToString("0.00"),
                                  text.NavigationTime.TotalMilliseconds.ToString("0.00"),
                                  text.DocumentSize));
            Console.WriteLine(TextTable.GetRow(
                                  "Newtonsoft",
                                  newtonsoft.ReadTime.TotalMilliseconds.ToString("0.00"),
                                  newtonsoft.WriteTime.TotalMilliseconds.ToString("0.00"),
                                  newtonsoft.NavigationTime.TotalMilliseconds.ToString("0.00"),
                                  newtonsoft.DocumentSize));
            Console.WriteLine(TextTable.GetRow(
                                  "Binary",
                                  binary.ReadTime.TotalMilliseconds.ToString("0.00"),
                                  binary.WriteTime.TotalMilliseconds.ToString("0.00"),
                                  binary.NavigationTime.TotalMilliseconds.ToString("0.00"),
                                  binary.DocumentSize));
            Console.WriteLine(TextTable.BottomLine);
        }
Пример #2
0
        public static void MeasurePerf(string json, string filename, int numberOfIterations = 1)
        {
            byte[] utf8ByteArray = Encoding.UTF8.GetBytes(json);

            // Text
            TimeSpan textReaderTime = JsonPerfMeasurement.MeasureReadPerformance(
                JsonReader.Create(utf8ByteArray),
                numberOfIterations);
            TimeSpan textWriterTime = JsonPerfMeasurement.MeasureWritePerformance(
                JsonWriter.Create(JsonSerializationFormat.Text),
                json,
                numberOfIterations);
            TimeSpan textNavigatorTime = JsonPerfMeasurement.MeasureNavigationPerformance(
                JsonNavigator.Create(utf8ByteArray),
                numberOfIterations);
            JsonExecutionTimes textExecutionTimes = new JsonExecutionTimes(
                textReaderTime,
                textWriterTime,
                textNavigatorTime,
                utf8ByteArray.Length,
                "Text");

            // Newtonsoft
            TimeSpan newtonsoftReaderTime = JsonPerfMeasurement.MeasureReadPerformance(
                NewtonsoftToCosmosDBReader.CreateFromString(json),
                numberOfIterations);
            TimeSpan newtonsoftWriterTime = JsonPerfMeasurement.MeasureWritePerformance(
                NewtonsoftToCosmosDBWriter.CreateTextWriter(),
                json,
                numberOfIterations);
            TimeSpan newtonsoftNavigatorTime = JsonPerfMeasurement.MeasureNavigationPerformance(
                new JsonNewtonsoftNavigator(json),
                numberOfIterations);
            JsonExecutionTimes newtonsoftExecutionTimes = new JsonExecutionTimes(
                newtonsoftReaderTime,
                newtonsoftWriterTime,
                newtonsoftNavigatorTime,
                json.Length,
                "Newtonsoft");

            // Binary
            byte[]   binaryPayload    = JsonTestUtils.ConvertTextToBinary(json);
            TimeSpan binaryReaderTime = JsonPerfMeasurement.MeasureReadPerformance(
                JsonReader.Create(binaryPayload),
                numberOfIterations);
            TimeSpan binarytWriterTime = JsonPerfMeasurement.MeasureWritePerformance(
                JsonWriter.Create(JsonSerializationFormat.Binary),
                json,
                numberOfIterations);
            TimeSpan binaryNavigatorTime = JsonPerfMeasurement.MeasureNavigationPerformance(
                JsonNavigator.Create(binaryPayload),
                numberOfIterations);
            JsonExecutionTimes binaryExecutionTimes = new JsonExecutionTimes(
                binaryReaderTime,
                binarytWriterTime,
                binaryNavigatorTime,
                binaryPayload.Length,
                "Binary");

            JsonPerfMeasurement.PrintStatisticsTable(
                filename,
                textExecutionTimes,
                newtonsoftExecutionTimes,
                binaryExecutionTimes);
        }