当前位置: 首页 > news >正文

云南工程建设总承包公司网站网站开发技术代码

云南工程建设总承包公司网站,网站开发技术代码,大连甘井子区地图,个人介绍微电影网站模板最近在研究web api 2#xff0c;看了一篇文章#xff0c;讲解如何提升性能的#xff0c; 在序列化速度的跑分中#xff0c;Protobuf一骑绝尘#xff0c;序列化速度快#xff0c;性能强#xff0c;体积小#xff0c;所以打算了解下这个利器 1#xff1a;安装篇 谷歌官方…最近在研究web api 2看了一篇文章讲解如何提升性能的 在序列化速度的跑分中Protobuf一骑绝尘序列化速度快性能强体积小所以打算了解下这个利器   1安装篇 谷歌官方没有提供.net的实现所以在nuget上找了一个移植的 Nuget里搜索Protobuf-net下载自动添加到项目中   2定义数据结构  using ProtoBuf;namespace ConsoleApplication1 {[ProtoContract]class Person{[ProtoMember(1)]public int Id { get; set; }[ProtoMember(2)]public string Name { get; set; }[ProtoMember(3)]public Address Address { get; set; }}[ProtoContract]class Address{[ProtoMember(1)]public string Line1 { get; set; }[ProtoMember(2)]public string Line2 { get; set; }} }    3封装简单操作类 按照作者使用习惯简单提供了一个Helper类 using System.IO; using System.Text; using ProtoBuf;namespace ConsoleApplication1 {public class ProtobufHelper{/// summary/// 序列化/// /summary/// typeparam nameT/typeparam/// param namet/param/// returns/returnspublic static string SerializeT(T t){using (MemoryStream ms new MemoryStream()){Serializer.SerializeT(ms, t);return Encoding.UTF8.GetString(ms.ToArray());}}/// summary/// 反序列化/// /summary/// typeparam nameT/typeparam/// param namecontent/param/// returns/returnspublic static T DeSerializeT(string content){using (MemoryStream ms new MemoryStream(Encoding.UTF8.GetBytes(content))){T t Serializer.DeserializeT(ms);return t;}}} }   4操作体验 代码很简单就不分开贴了 using System; using System.Collections.Generic; using System.IO;namespace ConsoleApplication1 {class Program{static void Main(string[] args){var p1 new Person{Id 1,Name 八百里开外,Address new Address{Line1 Line1,Line2 Line2}};var p2 new Person{Id 2,Name 一枪,Address new Address{Line1 Flat Line1,Line2 Flat Line2}};ListPerson pSource new ListPerson() { p1, p2 };string content ProtobufHelper.SerializeListPerson(pSource);Console.Write(content);//写入文件File.WriteAllText(D://hello.txt, content);Console.WriteLine(\r\n****解析部分*****);ListPerson pResult ProtobufHelper.DeSerializeListPerson(content);foreach (Person p in pResult){Console.WriteLine(p.Name);}Console.Read();}} } 控制台运行结果   同样的数据和Json所占用空间对比高下立判   后记 protobuf虽然有千般好但是我们是在 web api上使用的前台js解析不了Protobuf所以只能用Json咯~ StackService虽然Github上有2K多个Star,但是收费的。。同样的事情web api 2也能做到所以也略过它。 最终作者选择了跑分测试里面的第二名Jil  https://github.com/kevin-montrose/Jil       1. With very minimal annotation on the class level [ProtoContract(ImplicitFields ImplicitFields.AllPublic)] // only required on the class level class PersonEntity {public string FirstName { get; set; }public string LastName { get; set; } }   2. Without any annotation (using RuntimeTypeModel) static void InitializeProtobufRunTime() {var assembly Assembly.GetAssembly(typeof(PlainEntities.PersonEntity));var types assembly.GetTypes();foreach (var t in types.Where(x x.Namespace.Contains(PlainEntities))){Console.WriteLine(Processing {0}, t.FullName);var meta RuntimeTypeModel.Default.Add(t, false);var index 1;// find any derived class for the entityforeach (var d in types.Where(x x.IsSubclassOf(t))){var i index;Console.WriteLine(\tSubtype: {0} - #{1}, d.Name, i);meta.AddSubType(i, d);}// then add the propertiesforeach (var p in t.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly).Where(x x.GetSetMethod() ! null)){var i index;Console.WriteLine(\tProperty: {0} - #{1}, p.Name, i);meta.AddField(i, p.Name);}} }   And both the above works quite well without any performance differences. ------------------TestBinaryEntities------------------Process: 100000 items, MemorySize: 7400705, Completed in: 3877 ms, Serialization took: 676 ms, Deserialization took: 2948 ms ----------------------------------TestProtobufFullyAnnotatedEntities----------------------------------Process: 100000 items, MemorySize: 3983490, Completed in: 682 ms, Serialization took: 164 ms, Deserialization took: 253 ms -------------------------------------TestProtobufImplicitAnnotatedEntities-------------------------------------Process: 100000 items, MemorySize: 3983490, Completed in: 595 ms, Serialization took: 104 ms, Deserialization took: 210 ms -------------------------------TestProtobufRuntimeRegistration-------------------------------Processing ProtobufTestConsole.PlainEntities.BaseEntitySubtype: PersonEntity - #1Property: Id - #2Property: Gender - #3Processing ProtobufTestConsole.PlainEntities.PersonEntityProperty: FirstName - #1Property: LastName - #2Property: Age - #3Process: 100000 items, MemorySize: 4083490, Completed in: 646 ms, Serialization took: 113 ms, Deserialization took: 232 ms Looking forward to get this in :) Also attached the sample project for reference  转载于:https://www.cnblogs.com/zhahost/p/5813627.html
http://www.huolong8.cn/news/233626/

相关文章:

  • 网站建设中所涉及的所有链接建设360官方下载官网
  • 创建网站步骤公司变更法人的流程
  • 运营网站团队建设wordpress 企业 下载
  • 建公司网站的详细步骤wordpress cdn 阿里
  • 扁平风格网站 模板免费下载园林设计公司网站
  • 南宁世尊商贸网站建设公司简单网站多少钱
  • 吉林省住房建设厅网站汕头网站制作找谁
  • 教新手做网站难吗全球做的比较好的网站
  • 网站空间就是主机吗新闻媒体网站开发文档
  • 国外网站为什么不用备案吕梁购物网站开发设计
  • 济南做网站互联网公司有哪些微信网站用什么做的
  • 做百度移动端网站优化搜狗指数官网
  • 百度公司给做网站吗如何卸载和安装wordpress
  • 门头沟青岛网站建设做头像的网站有哪些
  • 阜新网站设计潍坊建设工程信息网站
  • 哪个网站做推销产品怎么注册网自己的网站吗
  • 网站站点查询做网站挣钱
  • 做优秀网站wordpress主题的安装教程
  • 安徽建站系统全面启动门户网站建设
  • 常州城投建设工程招标有限公司网站微信app下载安卓版官方下载
  • 肥城市住房和城乡建设厅网站手机能看禁止网站的浏览器
  • 做木质的网站二手设备回收做哪个网站好
  • 谷歌网站全网营销公司
  • win7做网站服务器网站重新解析
  • 做网站公司在丹麦传奇手游大型网站
  • 领域网站建设深圳罗湖互联网公司
  • 58同城做网站的电话电商网站建设企业
  • 企业网站制作公司有哪些网络营销外包
  • 可以做烟的网站吗企业网站备案资料
  • 加关键词的网站1个百度指数代表多少搜索