Beispiel #1
0
        private static void RunSerializationBenchmark_SourceGenerator <T>()
        {
            var sw = new Stopwatch();

            if (typeof(T) == typeof(Location))
            {
                Location value = DataGenerator.Generate <Location>();

                sw.Start();
                string json = JsonSerializer.Serialize(value, (JsonTypeInfo <Location>)JsonContext.Instance.Location);
                sw.Stop();
            }
            else if (typeof(T) == typeof(LoginViewModel))
            {
                LoginViewModel value = DataGenerator.Generate <LoginViewModel>();

                sw.Start();
                string json = JsonSerializer.Serialize(value, (JsonTypeInfo <LoginViewModel>)JsonContext.Instance.LoginViewModel);
                sw.Stop();
            }
            else if (typeof(T) == typeof(IndexViewModel))
            {
                IndexViewModel value = DataGenerator.Generate <IndexViewModel>();

                sw.Start();
                string json = JsonSerializer.Serialize(value, JsonContext.Instance.IndexViewModel);
                sw.Stop();
            }

            Console.WriteLine(sw.ElapsedMilliseconds);
        }
Beispiel #2
0
        private static void RunSerializationBenchmark_Utf8Json <T>()
        {
            T value = DataGenerator.Generate <T>();

            var sw = new Stopwatch();

            sw.Start();
            Utf8Json.JsonSerializer.ToJsonString(value);
            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds);
        }
Beispiel #3
0
        private static void RunSerializationBenchmark_JsonNet <T>()
        {
            T value = DataGenerator.Generate <T>();

            var sw = new Stopwatch();

            sw.Start();
            Newtonsoft.Json.JsonConvert.SerializeObject(value);
            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds);
        }
Beispiel #4
0
        private static void RunSerializationBenchmark_Jil <T>()
        {
            T value = DataGenerator.Generate <T>();

            var sw = new Stopwatch();

            sw.Start();
            Jil.JSON.Serialize <T>(value, Jil.Options.ISO8601);
            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds);
        }
Beispiel #5
0
        // Serialization methods.
        private static void RunSerializationBenchmark_Default <T>()
        {
            T value = DataGenerator.Generate <T>();

            // System.Text.Json
            var options = new JsonSerializerOptions();

            var sw = new Stopwatch();

            sw.Start();
            JsonSerializer.Serialize(value, options);
            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds);
        }