Ejemplo n.º 1
0
 /// <summary>Displays a result described by result.</summary>
 /// <param name="result">The result.</param>
 private static void DisplayResult(TimingResult result)
 {
     Console.WriteLine(string.Empty);
     Console.WriteLine($"Results of file: {result.Filename}, {result.FileSize} bytes");
     Console.WriteLine($"{result.LibraryName}:");
     Console.WriteLine($"           Setup: {result.SetupTime / 1000.0}s");
     Console.WriteLine($"     First Parse: {result.FirstParseTime / 1000.0}s");
     Console.WriteLine($" First Serialize: {result.FirstSerializeTime / 1000.0}s");
     Console.WriteLine($"    Looped Parse: {result.LoopedParseTime / 1000.0}s (avg: {(result.LoopedParseTime / 1000.0) / result.LoopCount})");
     Console.WriteLine($"Looped Serialize: {result.LoopedSerializeTime / 1000.0}s (avg: {(result.LoopedSerializeTime / 1000.0) / result.LoopCount})");
 }
Ejemplo n.º 2
0
        /// <summary>Tests net API.</summary>
        /// <param name="filename">Filename of the file.</param>
        /// <param name="contents">The contents.</param>
        /// <param name="loops">   The loops.</param>
        /// <returns>A TimingResult.</returns>
        private static TimingResult TestNetApi(string filename, string contents, int loops)
        {
            Version version = System.Reflection.Assembly.GetAssembly(typeof(FhirJsonParser)).GetName().Version;

            TimingResult timingResult = new TimingResult(filename, contents.Length, $"FHIR Net API, R4: {version}", loops);

            Console.WriteLine($"Measuring {timingResult.Filename} with {timingResult.LibraryName}...");

            Stopwatch timer = Stopwatch.StartNew();

            FhirJsonParser jsonParser = new FhirJsonParser(
                new ParserSettings
            {
                AcceptUnknownMembers   = true,
                AllowUnrecognizedEnums = true,
            });

            FhirJsonSerializer jsonSerializer = new FhirJsonSerializer(
                new SerializerSettings
            {
                AppendNewLine = false,
                Pretty        = false,
            });

            timingResult.SetupTime = timer.ElapsedMilliseconds;

            timer.Restart();

            var firstParsed = jsonParser.Parse(contents);

            timingResult.FirstParseTime = timer.ElapsedMilliseconds;

            if (firstParsed == null)
            {
                Console.WriteLine($"Parse failed!");
                timingResult.FailureCount++;
            }

            timer.Restart();
            string firstSerialized = jsonSerializer.SerializeToString(firstParsed);

            timingResult.FirstSerializeTime = timer.ElapsedMilliseconds;

            if (string.IsNullOrEmpty(firstSerialized))
            {
                Console.WriteLine($"Serialize failed!");
                timingResult.FailureCount++;
            }

            timingResult.ResourceType = firstParsed.GetType().Name;

            firstSerialized = null;

            timer.Restart();
            for (int i = 0; i < loops; i++)
            {
                var typed = jsonParser.Parse(contents);
                if (typed == null)
                {
                    Console.WriteLine($"Parse failed!");
                    timingResult.FailureCount++;
                }
            }

            timingResult.LoopedParseTime = timer.ElapsedMilliseconds;

            timer.Restart();
            for (int i = 0; i < loops; i++)
            {
                string serialized = jsonSerializer.SerializeToString(firstParsed);
                if (string.IsNullOrEmpty(serialized))
                {
                    Console.WriteLine($"Serialize failed!");
                    timingResult.FailureCount++;
                }
            }

            timingResult.LoopedSerializeTime = timer.ElapsedMilliseconds;

            return(timingResult);
        }
Ejemplo n.º 3
0
        /// <summary>Tests basic newton soft.</summary>
        /// <param name="filename">Filename of the file.</param>
        /// <param name="contents">The contents.</param>
        /// <param name="loops">   The loops.</param>
        /// <returns>A TimingResult.</returns>
        private static TimingResult TestBasicNewtonSoft(string filename, string contents, int loops)
        {
            TimingResult timingResult = new TimingResult(filename, contents.Length, "CSharpBasic-Newtonsoft", loops);

            Console.WriteLine($"Measuring {timingResult.Filename} with {timingResult.LibraryName}...");

            Stopwatch timer = Stopwatch.StartNew();

            Newtonsoft.Json.JsonConverter converter = new fhirNewtonsoft.ResourceConverter();

            timingResult.SetupTime = timer.ElapsedMilliseconds;

            timer.Restart();

            var firstParsed = Newtonsoft.Json.JsonConvert.DeserializeObject <fhirNewtonsoft.Resource>(contents, converter);

            timingResult.FirstParseTime = timer.ElapsedMilliseconds;

            if (firstParsed == null)
            {
                Console.WriteLine($"Parse failed!");
                timingResult.FailureCount++;
            }

            timer.Restart();
            string firstSerialized = Newtonsoft.Json.JsonConvert.SerializeObject(firstParsed);

            timingResult.FirstSerializeTime = timer.ElapsedMilliseconds;

            if (string.IsNullOrEmpty(firstSerialized))
            {
                Console.WriteLine($"Serialize failed!");
                timingResult.FailureCount++;
            }

            firstSerialized = null;

            timingResult.ResourceType = firstParsed.GetType().Name;

            timer.Restart();
            for (int i = 0; i < loops; i++)
            {
                var typed = Newtonsoft.Json.JsonConvert.DeserializeObject <fhirNewtonsoft.Resource>(contents, converter);
                if (typed == null)
                {
                    Console.WriteLine($"Parse failed!");
                    timingResult.FailureCount++;
                }
            }

            timingResult.LoopedParseTime = timer.ElapsedMilliseconds;

            timer.Restart();
            for (int i = 0; i < loops; i++)
            {
                string serialized = Newtonsoft.Json.JsonConvert.SerializeObject(firstParsed);
                if (string.IsNullOrEmpty(serialized))
                {
                    Console.WriteLine($"Serialize failed!");
                    timingResult.FailureCount++;
                }
            }

            timingResult.LoopedSerializeTime = timer.ElapsedMilliseconds;

            return(timingResult);
        }
Ejemplo n.º 4
0
        /// <summary>Tests create structure 2.</summary>
        /// <param name="filename">Filename of the file.</param>
        /// <param name="contents">The contents.</param>
        /// <param name="loops">   The loops.</param>
        /// <returns>A TimingResult.</returns>
        private static TimingResult TestCS2(string filename, string contents, int loops)
        {
            TimingResult timingResult = new TimingResult(filename, contents.Length, "CS2", loops);

            Console.WriteLine($"Measuring {timingResult.Filename} with {timingResult.LibraryName}...");

            Stopwatch timer = Stopwatch.StartNew();

            var serializeOptions = new System.Text.Json.JsonSerializerOptions();

            //serializeOptions.Converters.Add(new Test.R4.ResourceConverter());

            timingResult.SetupTime = timer.ElapsedMilliseconds;

            timer.Restart();

            var firstParsed = System.Text.Json.JsonSerializer.Deserialize(contents, typeof(Fhir.R4.Models.Resource), serializeOptions);

            timingResult.FirstParseTime = timer.ElapsedMilliseconds;

            if (firstParsed == null)
            {
                Console.WriteLine($"Parse failed!");
                timingResult.FailureCount++;
            }

            timer.Restart();
            string firstSerialized = System.Text.Json.JsonSerializer.Serialize(firstParsed, typeof(Fhir.R4.Models.Resource));

            timingResult.FirstSerializeTime = timer.ElapsedMilliseconds;

            if (string.IsNullOrEmpty(firstSerialized))
            {
                Console.WriteLine($"Serialize failed!");
                timingResult.FailureCount++;
            }

            firstSerialized = null;

            timingResult.ResourceType = firstParsed.GetType().Name;

            timer.Restart();
            for (int i = 0; i < loops; i++)
            {
                var typed = System.Text.Json.JsonSerializer.Deserialize(contents, typeof(Fhir.R4.Models.Resource), serializeOptions);
                if (typed == null)
                {
                    Console.WriteLine($"Parse failed!");
                    timingResult.FailureCount++;
                }
            }

            timingResult.LoopedParseTime = timer.ElapsedMilliseconds;

            timer.Restart();
            for (int i = 0; i < loops; i++)
            {
                string serialized = System.Text.Json.JsonSerializer.Serialize(firstParsed, typeof(Fhir.R4.Models.Resource));
                if (string.IsNullOrEmpty(serialized))
                {
                    Console.WriteLine($"Serialize failed!");
                    timingResult.FailureCount++;
                }
            }

            timingResult.LoopedSerializeTime = timer.ElapsedMilliseconds;

            return(timingResult);
        }