测试代码Zonciu/SerializationTest.cs

源自neuecc/ZeroFormatterBenchmark.cs

NuGet包及其版本

mgravell/protobuf-net 2.3.2(非官方实现,官方无.NET实现)
msgpack/msgpack-cli 1.0.0-beta2(官方实现)
neuecc/MessagePack 1.7.2(非官方实现)
JamesNK/Newtonsoft.Json 10.0.3

兼容性

protobuf-net

  • 不支持无Contract Attribute的模型
  • 自带Attribute
  • 支持System.Runtime.Serialization Attribute

MsgPack-Cli

  • 支持无Contract Attribute的模型
  • 自带Attribute
  • 支持System.Runtime.Serialization Attribute

MessagePack

  • 支持无Contract Attribute的模型
  • 自带Attribute
  • 支持System.Runtime.Serialization Attribute

Newtonsoft.Json

  • 支持无Contract Attribute的模型
  • 自带Attribute
  • 支持System.Runtime.Serialization Attribute

测试结果

mgravell/protobuf-net
Serialize 4.195 ms
Deserialize 10.0423 ms
ReSerialize 4.1817 ms
Size of Binary 36.00 B
mgravell/protobuf-net
Serialize 4.172 ms
Deserialize 10.0139 ms
ReSerialize 4.1776 ms
Size of Binary 36.00 B
mgravell/protobuf-net
Serialize 4.4121 ms
Deserialize 10.2684 ms
ReSerialize 4.2439 ms
Size of Binary 36.00 B Official MsgPack-Cli
Serialize 6.9675 ms
Deserialize 14.4727 ms
ReSerialize 6.7491 ms
Size of Binary 36.00 B
Official MsgPack-Cli
Serialize 6.7087 ms
Deserialize 14.4588 ms
ReSerialize 6.9524 ms
Size of Binary 36.00 B
Official MsgPack-Cli
Serialize 6.7676 ms
Deserialize 14.5932 ms
ReSerialize 6.9552 ms
Size of Binary 36.00 B neuecc/MessagePack-CSharp
Serialize 3.703 ms
Deserialize 4.3366 ms
ReSerialize 3.6741 ms
Size of Binary 32.00 B
neuecc/MessagePack-CSharp
Serialize 3.7056 ms
Deserialize 4.6376 ms
ReSerialize 3.6672 ms
Size of Binary 32.00 B
neuecc/MessagePack-CSharp
Serialize 3.6871 ms
Deserialize 4.2972 ms
ReSerialize 3.6756 ms
Size of Binary 32.00 B Newtonsoft.Json
Serialize 17.5037 ms
Deserialize 33.8181 ms
ReSerialize 21.2306 ms
Size of Binary 90.00 B
Newtonsoft.Json
Serialize 18.4885 ms
Deserialize 35.5003 ms
ReSerialize 17.4223 ms
Size of Binary 90.00 B
Newtonsoft.Json
Serialize 18.1058 ms
Deserialize 32.0834 ms
ReSerialize 23.5259 ms
Size of Binary 90.00 B mgravell/protobuf-net
Serialize 6546.5884 ms
Deserialize 11488.7313 ms
ReSerialize 6709.2795 ms
Size of Binary 37.11 KB
mgravell/protobuf-net
Serialize 6564.3259 ms
Deserialize 11431.9974 ms
ReSerialize 6679.0116 ms
Size of Binary 37.11 KB
mgravell/protobuf-net
Serialize 6561.8096 ms
Deserialize 11476.1318 ms
ReSerialize 6668.9106 ms
Size of Binary 37.11 KB Official MsgPack-Cli
Serialize 5617.6389 ms
Deserialize 14581.9512 ms
ReSerialize 5578.6621 ms
Size of Binary 38.82 KB
Official MsgPack-Cli
Serialize 5590.4476 ms
Deserialize 14763.014 ms
ReSerialize 5533.6327 ms
Size of Binary 38.82 KB
Official MsgPack-Cli
Serialize 5607.3836 ms
Deserialize 14615.2356 ms
ReSerialize 5585.7651 ms
Size of Binary 38.82 KB neuecc/MessagePack-CSharp
Serialize 3065.3312 ms
Deserialize 4371.5859 ms
ReSerialize 3062.9087 ms
Size of Binary 32.83 KB
neuecc/MessagePack-CSharp
Serialize 3116.9423 ms
Deserialize 4392.1279 ms
ReSerialize 3061.0422 ms
Size of Binary 32.83 KB
neuecc/MessagePack-CSharp
Serialize 3080.5855 ms
Deserialize 4385.2026 ms
ReSerialize 3054.3972 ms
Size of Binary 32.83 KB Newtonsoft.Json
Serialize 13303.1545 ms
Deserialize 24219.7497 ms
ReSerialize 13346.126 ms
Size of Binary 86.81 KB
Newtonsoft.Json
Serialize 13362.7296 ms
Deserialize 24238.1881 ms
ReSerialize 13332.8785 ms
Size of Binary 86.81 KB
Newtonsoft.Json
Serialize 13399.7856 ms
Deserialize 24197.9922 ms
ReSerialize 13325.7399 ms
Size of Binary 86.81 KB neuecc/MessagePack-CSharp without Attribute
Serialize 3.9342 ms
Deserialize 4.9817 ms
ReSerialize 3.9434 ms
Size of Binary 65.00 B
neuecc/MessagePack-CSharp without Attribute
Serialize 3.9854 ms
Deserialize 4.9978 ms
ReSerialize 3.9498 ms
Size of Binary 65.00 B
neuecc/MessagePack-CSharp without Attribute
Serialize 3.9393 ms
Deserialize 5.1384 ms
ReSerialize 3.9293 ms
Size of Binary 65.00 B neuecc/MessagePack-CSharp without Attribute
Serialize 3968.4564 ms
Deserialize 4912.953 ms
ReSerialize 4082.8229 ms
Size of Binary 65.06 KB
neuecc/MessagePack-CSharp without Attribute
Serialize 3967.5422 ms
Deserialize 4912.2183 ms
ReSerialize 4059.2614 ms
Size of Binary 65.06 KB
neuecc/MessagePack-CSharp without Attribute
Serialize 3952.6747 ms
Deserialize 4974.3738 ms
ReSerialize 4066.7528 ms
Size of Binary 65.06 KB

单对象序列化、反序列化、再序列化时间

多对象数组序列化、反序列化、再序列化时间

单对象序列化后数据大小

多对象数组序列化后数据大小

结论

neuecc/MessagePack表现最优,官方MsgPack-Cli表现比较差,Protobuf不支持无Contract Attribute模型,意味着需要侵入模型。

使用MessagePack,模型添加Contract Attribute并添加int型Order,比不添加Attribute或添加string型key快一点点,序列化后数据量明显减少,原因是不使用Attribute或使用string型Attribute key时,是以成员名称或key string作为索引,反之使用int型索引。

.NET Core protobuf-net、MessagePack、Json.NET序列化/反序列化性能测试的更多相关文章

  1. 二进制数据的序列化反序列化和Json的序列化反序列化的重要区别

    前言:最近一个一个很奇怪的问题,很明白的说,就是没看懂,参照下面的代码: /// <summary> /// 反序列化对象 /// </summary> /// <typ ...

  2. 项目收集-AutoMapper使用,事务,Json.Net序列化反序列化,代码生成调用等

    using System; using AutoMapper; using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace Console ...

  3. 05-06 Flutter JSON和序列化反序列化、创建模型类转换Json数据、轮播图数据渲染:Flutter创建商品数据模型 、请求Api接口渲染热门商品 推荐商品

    Config.dart class Config{ static String domain='http://jd.itying.com/'; } FocusModel.dart class Focu ...

  4. Newtonsoft.Json.Linq 序列化 反序列化等知识

    1.反序列化实体类 //使用JObject读写字符串:JObject j = JObject.Parse(data);IEnumerable<JProperty> properties = ...

  5. php json与xml序列化/反序列化

    在web开发中对象的序列化与反序列化经常使用,比较主流的有json格式与xml格式的序列化与反序列化,今天想写个jsop的小demo,结果发现不会使用php序列化,查了一下资料,做个笔记 简单数组js ...

  6. 基于.NET CORE微服务框架 -谈谈surging 的messagepack、protobuffer、json.net 序列化

    1.前言 surging内部使用的是高性能RPC远程服务调用,如果用json.net序列化肯定性能上达不到最优,所以后面扩展了protobuf,messagepack序列化组件,以支持RPC二进制传输 ...

  7. 在Asp.Net Core 3.0中如何使用 Newtonsoft.Json 库序列化数据

    在.Net Core 3.0中 内置了一套Json序列化/反序列化方案,默认可以不再依赖,不再支持   Newtonsoft.Json. 但是.NET Core 3.0 System.Text.Jso ...

  8. 序列化 反序列化 MessagePack for C#

    阅读目录 快速序列化组件MessagePack介绍 简介 使用 快速开始 分析器 内置的支持类型 对象序列化 DataContract兼容性 序列化不可变对象(序列化构造器) 序列化回调 Union ...

  9. 超越 JSON: Spearal 序列化协议简介

      Spearal 是一个新的开源的序列化协议,这个协议旨在初步替换JSON 将HTML和移动应用连接到Java的后端. Spearal的主要目的是提供一个序列协议,这个协议即使是在端点间传输的复杂的 ...

随机推荐

  1. PTA_Have fun with numbers(C++)

    #include<iostream> #include<cstring> using namespace std; int main() { ; ]="; ]={}, ...

  2. Maven导入项目时报错 Could not calculate build plan

    Could not calculate build plan: Plugin org.apache.maven.plugins:maven-war-plugin:2.2 or one of its d ...

  3. Linux-信号量与P,V操作

    Linux-信号量与P,V操作 内容 使用信号量实现进程互斥 使用信号量及PV实现子进程读写同步 机理 Linux信号量集 Linux信号量作为IPC机制的一种,与其他通信方式类似,Linux也是通过 ...

  4. git 修改用户名和密码

    初次运行 Git 前的配置 一般在新的系统上,我们都需要先配置下自己的 Git 工作环境.配置工作只需一次,以后升级时还会沿用现在的配置.当然,如果需要,你随时可以用相同的命令修改已有的配置. Git ...

  5. spring 应用

    Spring框架本身会托管bean. 1.使用时需要注意对于包本身扫描配置. 2.使用注解本身包需要在扫描路径下.

  6. 封装PDO函数

    funPDO.php <?php /** * @title: 封装PDO函数 * * @Features: * 1. 封装 SELECT ,INSERT,DELETE,UPDATE 操作 @do ...

  7. 把H5打包成IOS APP其实可以很简单!签名?越狱?都不需要!

    很多小伙伴都在开发自己的app, 有的实现实现比较简单,就是一个h5页面,然后想要打包成app发布出去. 这个想法很单纯 打包生成个app这个是很简单的,网上一堆打包工具,分分钟可以完成 BUT…… ...

  8. 用cmd命令执行SQL脚本

    1.简单说明 osql 为SQL Server的命令 2.要在cmd中执行该命令,一般安装SQL Server后该命令对应的路径会自动添加到系统环境变量中. 3.-S 表示要连接的数据库 -U表示登录 ...

  9. xpath使用方法

    一.选取节点常用的路劲表达式: 表达式 描述 实例   nodename 选取nodename节点的所有子节点 xpath(‘//div’) 选取了div节点的所有子节点 / 从根节点选取 xpath ...

  10. Mesos源码分析(5): Mesos Master的启动之四

      5. Create an instance of allocator.   代码如下   Mesos源码中默认的Allocator,即HierarchicalDRFAllocator的位置在$ME ...