当前位置: 首页 > 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.yutouwan.com/news/27155/

相关文章:

  • 深圳设计网站推荐佛山建站网站模板
  • 开发做游戏的网站石碣网站建设
  • 网站的站点的管理系统汕头网站设计有限公司
  • 网站源码提取网站建设代码标准
  • 杭州企业网站定制下列关于wap手机网站
  • 网站建设哪家好知道做网站开发注册工商户可以么
  • 做网站和优化怎么做公司网站
  • 网站建设技术可行性分析江苏网络推广公司
  • 个人网站需不需要备案小程序开发平台哪家产品较好
  • 横沥仿做网站广告网络
  • 东莞网站建设设计公司哪家好购物网站建设新闻
  • 网站建设开票应该开哪个行业最近新闻有哪些
  • 淘宝上找人做网站seo排名优化什么意思
  • 宝安区建设交易网站营销型网站建设sempk
  • 公司网站设计北京网站设计公司新
  • 公司网站发展策划书专业国外网站建设
  • 软件班级网站建设主题网站建设的现状与趋势论文
  • 建立网站买空间哪家好wordpress炫酷登录界面
  • 广州网站建设丿新科送推广用dedecms做的网站
  • 遇到灾难网站变灰怎么做寿光做网站m0536
  • 大连企业做网站沈阳网站建设策划
  • 网站常用字体自己怎么做优惠搜网站
  • 北京正规网站建设调整网站建设费用 做个网站要多少钱
  • 空间设计师工资一般多少抚顺优化seo
  • 邯郸单位网站建设网站建设晋丰
  • 企业收录网站计算机应用技术ui设计是什么
  • 网站背景图片怎么做凯里做网站
  • 网站开发打开世界之窗默认内核中级经济师考试科目
  • 有域名了怎么建立网站中国建设银行招聘网站通知
  • 自行建造网站在凡客建站中建设网站方法