UNITY Serializer 序列化 横向对比
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 序列化 横向对比的更多相关文章
- Rest_framework Serializer 序列化 (含源码浅解序列化过程)
目录 Rest_framework Serializer 序列化 序列化与反序列化中不得不说的感情纠葛 三角恋之 save/update/create 四角恋之 序列化参数instance/data/ ...
- 中国云运营商横向对比——IaaS服务对标
前言: 随着互联网行业的快速发展,云服务器的使用越来越普遍.中国的云服务器提供商数量也在增加,市场上有大大小小多家云服务器提供商.然而,为了在众多服务提供商中脱颖而出,国内云服务器运营商商也在不断的利 ...
- 转:【AI每日播报】从TensorFlow到Theano:横向对比七大深度学习框架
http://geek.csdn.net/news/detail/139235 说到近期的深度学习框架,TensorFlow火的不得了,虽说有专家在朋友圈大声呼吁,不能让TensorFlow形成垄断地 ...
- Django:前后端分离 djangorestframework开发API接口 serializer序列化认证组件
参考:https://blog.csdn.net/zhangmengran/article/details/84887206 目的: 使用serializer序列化器将QuerySet数据序列化为js ...
- 横向对比分析Python解析XML的四种方式
横向对比分析Python解析XML的四种方式 在最初学习PYTHON的时候,只知道有DOM和SAX两种解析方法,但是其效率都不够理想,由于需要处理的文件数量太大,这两种方式耗时太高无法接受. 在网络搜 ...
- jQuery中的serializer序列化—炒鸡好用
jQuery.serializer()序列化 serialize()函数用于序列化一组表单元素,将表单内容编码为用于提交的字符串. serialize()函数常用于将表单内容序列化,以便用于AJAX提 ...
- DRF框架之Serializer序列化器的序列化操作
在DRF框架中,有两种序列化器,一种是Serializer,另一种是ModelSerializer. 今天,我们就先来学习一下Serializer序列化器. 使用Serializer序列化器的开发步骤 ...
- DRF框架之Serializer序列化器的反序列化操作
昨天,我们完成了Serializer序列化器的反序列化操作,那么今天我们就来学习Serializer序列化器的最后一点知识,反序列化操作. 首先,我们定要明确什么是反序列化操作? 反序列化操作:JOS ...
- Serializer序列化/反序列化DateTime少了8小时问题解决
1.举例子 JavascriptSerializer serializer = new JavascriptSerializer(); DateTime now = DateTime.Parse(&q ...
随机推荐
- thymeleaf实现热部署
热部署可以在修改页面之后,不重新启动服务器也能查看修改效果. 1.导入依赖,我用的是gradle,使用maven的可以去https://mvnrepository.com/寻找对应的依赖 compil ...
- 原生js拖拽、jQuery拖拽、vue自定义指令拖拽
原生js拖拽: <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...
- Linux性能优化实战学习笔记:第二十八讲
一.案例环境描述 1.环境准备 2CPU,4GB内存 预先安装docker sysstat工具 apt install docker.io sysstat nake git 案例总共由三个容器组成: ...
- Log-Structured Merge Tree (LSM Tree)
一种树,适合于写多读少的场景.主要是利用了延迟更新.批量写.顺序写磁盘(磁盘sequence access比random access快). 背景 回顾数据存储的两个“极端”发展方向 加快读:加索引( ...
- [LeetCode] 894. All Possible Full Binary Trees 所有可能的满二叉树
A full binary tree is a binary tree where each node has exactly 0 or 2 children. Return a list of al ...
- [LeetCode] 767. Reorganize String 重构字符串
Given a string S, check if the letters can be rearranged so that two characters that are adjacent to ...
- API加密框架原理解密
关于框架的使用文章请参考: 前后端API交互如何保证数据安全性?:http://cxytiandi.com/blog/detail/20235 API数据加密框架monkey-api-encrypt: ...
- mysql 字段修改汇总
-- 增加 ALTER TABLE `gdm_nursing_patient` ADD COLUMN `due_date` date DEFAULT NULL COMMENT '名称' AFTER ...
- 热情组——项目冲刺 Day2
项目相关 作业相关 具体描述 班级 班级链接 作业要求 链接地址 团队名称 热情组 作业目标 实现软件的生成,以及在福大的传播 Github链接 链接地址 SCRUM部分: 成员昵称 昨日目标 开始时 ...
- ZROI1153 【线上训练3】数个数
ZROI1153 [线上训练3]数个数 传送门 一道非常有意思的题,涵盖了各种知识点. 首先,很显然,这是个容斥.容斥可以过掉\(30pts\). 这里我们考虑容斥+DP. 我们令\(dp[i][j] ...