UNITY Serializer 序列化 横向对比

关于序列化,无论是.net还是unity自身都提供了一定保障。然而人总是吃着碗里想着锅里,跑去github挖个宝是常有的事。看看各家大佬的本事。最有趣的就是每个开源库首页上各个都有吊打隔壁的意思。

测试结果

测试环境

  • Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz
  • 16.0 GB
  • Unity 2018.3.9f1 .NET 4.x
  • 测试均为Windowns Standalone Release配置
开源库 序列化 反序列化 继承多态 il2cpp il2cpp序列化 il2cpp反序列化 需要外加代码或标签 高级特性
BinaryFormatter 80 80 yes yes 65 58 no .NET自带
JsonUtility 16 31 no yes 20 16 no Unity自带
OdinSerializer 22 48 yes yes 211 244 no Unity.Object也能参与序列化
MessagePack-CSharp 1 3 no no N/A N/A yes 据说可生通过标记配合模板成代码进行il2cpp
NetSerializer 5 10 yes no N/A N/A yes MPL协议谨慎
Newtonsoft.Json 25 29 yes no N/A N/A no

测试用例

https://github.com/oplusx/UnitySerializerBenchmarks

using MessagePack;
using Newtonsoft.Json;
using OdinSerializer;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using UnityEngine;
using Debug = UnityEngine.Debug; public class test : MonoBehaviour
{
[Serializable]
[MessagePackObject]
public class No1
{
[Key(0)]
public int no1;
[Key(1)]
public string hehe = "hehe";
}
[Serializable]
[MessagePackObject]
public class No2 : No1
{
[Key(0)]
public int no2;
}
[Serializable]
[MessagePackObject]
public class Set
{
[Key(0)]
public List<No1> set = new List<No1>();
}
// Start is called before the first frame update
void Start()
{
var stream = new MemoryStream();
var set = new Set();
for(int i = 0; i < 10; i++)
{
set.set.Add(new No1());
set.set.Add(new No2());
} List<Type> types = new List<Type>();
types.Add(typeof(No1));
types.Add(typeof(No2));
types.Add(typeof(Set));
var sw = Stopwatch.StartNew(); BinaryFormatter b = new BinaryFormatter();
stream = new MemoryStream();
sw.Restart();
for (int i = 0; i < 1000; i++)
{
stream.Seek(0, SeekOrigin.Begin);
b.Serialize(stream, set);
}
sw.Stop();
Debug.LogFormat("BinaryFormatter Writing {0} ms", sw.ElapsedMilliseconds); sw.Restart();
for (int i = 0; i < 1000; i++)
{
stream.Seek(0, SeekOrigin.Begin);
var newobj = b.Deserialize(stream);
}
sw.Stop();
Debug.LogFormat("BinaryFormatter Reading {0} ms", sw.ElapsedMilliseconds);
}
}

总结

其实在mono环境下的序列化之争,的确有把.net和unity干翻的意思,然而考虑到多平台,特别是il2cpp之后,选择就少了很多,具体还是要根据实际应用场景了。

UNITY Serializer 序列化 横向对比的更多相关文章

  1. Rest_framework Serializer 序列化 (含源码浅解序列化过程)

    目录 Rest_framework Serializer 序列化 序列化与反序列化中不得不说的感情纠葛 三角恋之 save/update/create 四角恋之 序列化参数instance/data/ ...

  2. 中国云运营商横向对比——IaaS服务对标

    前言: 随着互联网行业的快速发展,云服务器的使用越来越普遍.中国的云服务器提供商数量也在增加,市场上有大大小小多家云服务器提供商.然而,为了在众多服务提供商中脱颖而出,国内云服务器运营商商也在不断的利 ...

  3. 转:【AI每日播报】从TensorFlow到Theano:横向对比七大深度学习框架

    http://geek.csdn.net/news/detail/139235 说到近期的深度学习框架,TensorFlow火的不得了,虽说有专家在朋友圈大声呼吁,不能让TensorFlow形成垄断地 ...

  4. Django:前后端分离 djangorestframework开发API接口 serializer序列化认证组件

    参考:https://blog.csdn.net/zhangmengran/article/details/84887206 目的: 使用serializer序列化器将QuerySet数据序列化为js ...

  5. 横向对比分析Python解析XML的四种方式

    横向对比分析Python解析XML的四种方式 在最初学习PYTHON的时候,只知道有DOM和SAX两种解析方法,但是其效率都不够理想,由于需要处理的文件数量太大,这两种方式耗时太高无法接受. 在网络搜 ...

  6. jQuery中的serializer序列化—炒鸡好用

    jQuery.serializer()序列化 serialize()函数用于序列化一组表单元素,将表单内容编码为用于提交的字符串. serialize()函数常用于将表单内容序列化,以便用于AJAX提 ...

  7. DRF框架之Serializer序列化器的序列化操作

    在DRF框架中,有两种序列化器,一种是Serializer,另一种是ModelSerializer. 今天,我们就先来学习一下Serializer序列化器. 使用Serializer序列化器的开发步骤 ...

  8. DRF框架之Serializer序列化器的反序列化操作

    昨天,我们完成了Serializer序列化器的反序列化操作,那么今天我们就来学习Serializer序列化器的最后一点知识,反序列化操作. 首先,我们定要明确什么是反序列化操作? 反序列化操作:JOS ...

  9. Serializer序列化/反序列化DateTime少了8小时问题解决

    1.举例子 JavascriptSerializer serializer = new JavascriptSerializer(); DateTime now = DateTime.Parse(&q ...

随机推荐

  1. JavaScript中的回调函数(callback)

    什么是回调函数 In computer programming, a callback is a piece of executable code that is passed as an argum ...

  2. Excel-查找函数

    1.VLOOKUP函数 该函数的语法规则如下: VLOOKUP(lookup_value,table_array,col_index_num,range_lookup) 多表关联查询---vlooku ...

  3. ABP 下载源码报错

    ASP.NET Boilerplate 下载地址应该是这个:https://github.com/aspnetboilerplate/aspnetboilerplate/tree/v1.5.2 下载的 ...

  4. [LeetCode] 450. Delete Node in a BST 删除二叉搜索树中的节点

    Given a root node reference of a BST and a key, delete the node with the given key in the BST. Retur ...

  5. 申请Github学生包(用学生证就行,免教育邮箱)

    GitHub教育包的福利: 大名鼎鼎的JetBrains给学生教师的免费个人许可 https://education.github.com/pack/redeem/jetbrains 有Github学 ...

  6. java web开发入门十一(idea maven mybatis自动代码生成)基于intellig idea

    6.idea maven mybatis逆向工程(代码生成器) 1.配置pom.xml 在plugins标签下添加mybatis-generator-maven-plugin <plugin&g ...

  7. golang web 方案

    概要 开发 web 框架 数据库 认证 日志 配置 静态文件服务 上传/下载 发布 docker 打包 部署中遇到的问题 时区问题 概要 轻量的基于 golang 的 web 开发实践. golang ...

  8. ECMAScript 初探 - 对象篇

    一.对象 如果你用过 C++ 或 Java,肯定熟悉类(class).在 ECMAScript 中并没有 "类" 这个词, 其对应的是 "对象定义",不过这太拗 ...

  9. BCompare注册文件+密钥被撤销解决方案

    注册码: rssAPVg2OpBjDVo3E0DhGWrjPIq0hsTSuNz13wTuzVHfb2mRgO9bZKn9Bl42D5YEyMSYPXsxzcb08dqbRlbzWNJzJXE6YVa ...

  10. Beta冲刺(8/7)——2019.5.30

    作业描述 课程 软件工程1916|W(福州大学) 团队名称 修!咻咻! 作业要求 项目Beta冲刺(团队) 团队目标 切实可行的计算机协会维修预约平台 开发工具 Eclipse 团队信息 队员学号 队 ...