zoukankan      html  css  js  c++  java
  • 微软自带的Serialization和Newtonsoft简单测试

    刚刚对这两个进行了一下小小的测试

    发现

    当转换的内容少的时候  微软自带的比Newtonsoft速度要快一些,内容多的时候反之,当内容多到一定量的时候微软自带的就不能转换了,需要修改一下MaxJsonLength的默认值,此处我改为:999999999,这个时候可以转换了,不过时间很长。

    添加50个对象:

    添加500个对象:

    添加5K对象:

    添加5W对象:

    添加50W对象:

    50W,修改完默认值:

    添加500W 对象:

    添加700W对象:

    微软自带的出不来了,报错了,这次我是把Newtonsoft移到上边了

    添加900W对象:

    图1

    图2

    代码如下:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Newtonsoft.Json;
    using System.Collections;
    using System.Diagnostics;
    using System.Web.Script.Serialization;
    
    namespace JsonNet
    {
        class Program
        {
            static void Main(string[] args)
            {
                Person p1 = new Person() { age = 23, name = "张三", sex = "N" };
    
                List<Person> arr = new List<Person>();
                for (int i = 0; i < 5000000; i++)
                {
                    arr.Add(p1);
    
                }
                Stopwatch watch1 = new Stopwatch();
                Stopwatch watch2 = new Stopwatch();
    
    
                watch1.Start();
                JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
                jsSerializer.MaxJsonLength = 999999999;
                string str = jsSerializer.Serialize(arr);
                Console.WriteLine("Serialization转换时间:" + watch1.Elapsed);
    
    
                watch2.Start();
                string strr = JsonConvert.SerializeObject(arr);
                Console.Write("Newtonsoft转换时间" + watch2.Elapsed);
    
                Console.ReadKey();
    
            }
        }
    
        public class Person
        {
            public string name;
            public int age;
            public string sex;
    
        }
    }
  • 相关阅读:
    [转载]从零开始学习OpenGL ES之一 – 基本概念
    ios中陀螺仪CoreMotion的使用
    如何在IOS中使用3D UI – CALayer的透视投影
    cocos3d加载3Dmax模型到ios中
    cocos2d 坐标系统参考
    PAT 1029 Median
    PAT 1028 List Sorting
    Linux中的进程调度(二)
    LaTeX学习(一)
    搬家
  • 原文地址:https://www.cnblogs.com/xiaoshi657/p/4617353.html
Copyright © 2011-2022 走看看