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 ...
随机推荐
- itsdangerous模块
使用场景: 在取消订阅时,可以在URL里序列化并且签名一个用户的ID或在任何的激活账户的链接或类似的情形下使用.这种情况下不需要生成一个一次性的token并把它们存到数据库中. 被签名的对象可以被存入 ...
- 2020年数据库概念与MySQL的安装与配置-从零基础入门MySQL-mysql8版本
作者 | Jeskson 来源 | 达达前端小酒馆 从零基础入门MySQL数据库基础课 数据的概念,简介,安装与配置,Windows平台下MySQL的安装与配置. 数据库的概念:数据库是一个用来存放数 ...
- [LeetCode] 914. X of a Kind in a Deck of Cards 一副牌中的X
In a deck of cards, each card has an integer written on it. Return true if and only if you can choos ...
- [LeetCode] 321. Create Maximum Number 创建最大数
Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum numb ...
- Centos.安装Goaccess1.2
下载 wget http://tar.goaccess.io/goaccess-1.2.tar.gz 解压 tar -xzvf goaccess-1.2.tar.gz 安装支持库GeoIP-devel ...
- Feign的介绍和使用
一.Feign的简介 Feign是一个声明式 WebService 客户端,使用Feign能够让编写Web Service 客户端更加简单,它的使用方法是定义一个接口,然后在上面添加注解,同时也支持J ...
- java登录点击验证码图片切换验证码无效
1.问题:我在写一个登录时需要添加一个验证码的功能,但是第一次可以生成验证码,但是点击的时候无法发起请求. 2.解决方案:在请求地址后面加一个时间戳,保证每次请求都不一样就可以了! window.on ...
- MongoDB学习笔记(五)
MongoDB 查看执行计划 MongoDB 中的 explain() 函数可以帮助我们查看查询相关的信息,这有助于我们快速查找到搜索瓶颈进而解决它,本文我们就来看看 explain() 的一些用法及 ...
- golang学习笔记----源码文件
GO源码文件
- PIE SDK直方图统计法
1.算法功能简介 图像直方图描述了图像中每个亮度值DN的像元数量的统计分布.它通过每个亮度值的像元数除以图像中总得像元数,即频率直方图.在很多遥感应用中,直方图是遥感图像中所包含的信息的一种有用的图示 ...