English 中文(简体)
ProtoBuf-Net 性能
原标题:ProtoBuf-Net Performance

举例如下:

第1类序列化所需时间是第2类序列化的近两倍吗?还是原生泡沫-网络将第1类中的字节作为已经序列化的数据处理?

Pseudo 示例 :

[ProtoContract]
class Class1
{
  [ProtoMember(1)]
  public byte[] SerializedData { get; set; }
}

[ProtoContract]
class Class2
{
  [ProtoMember(1)]
  public Class3 NonSerializedData { get; set; }
}

[ProtoContract]
class Class3
{
  [ProtoMember(1)]
  public string Address{ get; set; }

  [ProtoMember(2)]
  public string ZipCode{ get; set; }

  [ProtoMember(2)]
  public string Country{ get; set; }
}

Class3 _c3 = new Class3() { Address = "MyAddress", ZipCode = "90210", Country = "AZ"  }

// Class 1 Serialization
Class1 _c1 = new C1();
_c1.SerializedData = protobuf.Serialize(_c3);

byte[] c1Bytes = protobuf.Serialize(_c1);

// Class 2 Serialization
Class2 _c2 = new Class2();
_c2.NonSerializedData = _c3;

byte[] c2Bytes = protobuf.Serialize(_c2);
问题回答

或者说,如果第1类中的字节已经按顺序排列的数据处理,原样布-net是否会处理该字节?

byte[] byte < genger > is 被作为原始数据处理(并被写入流流,而没有任何额外的处理程序),但还需要一些小东西来序列化 Class1 - 写入页眉字段和一般间接费用。在处理单个天体时,两种方法都足够快,以至于任何差异都无实际意义。但是,在数量大的情况下,我有充分的理由怀疑,序列化 Class2 将明显更快,因为处理单一的序列化管道可以避免一些间接费用。

第1类序列化所需时间是第2类序列化的近两倍吗?

这将是一个非常好的配置, 但取决于您的典型数据。 只有您才能找到实际数字 。 我期望“ 稍长一点 ” 。 在这两个例子中, 我比较了“ 序列化第3类的成本 3 ”, 然后将由该类输出组成的第1类序列化, 与“ 序列化第3类由第1类实例组成的第3类的成本 ” 。

事实上,如果速度是你们关心的首要问题,我希望最佳办法将是:

[ProtoContract]
class Class2
{
  [ProtoMember(1, DataFormat = DataFormat.Group)]
  public Class3 NonSerializedData { get; set; }
}

这个微妙的tweak 表示它可以以非缓冲的、只前方的方式(通过使用终止者而不是长度前缀)写入 Class3 。 唯一的原因是谷歌明显偏爱长度前缀方法。





相关问题
WCF hosting in .NET compact framework

I would like to host a service on a WinCE device. The WinCE device is the host which can be accessed(control and data acquisition) by multiple clients (PC or WinCE) over serial port, TCP, USB etc. I ...

protobuf-net [de]serializing across assembly boundaries

I have a base class in one assembly and a large number of generated classes in another that inherit from the base class. Using protobuf-net (r282) to serialize a list of the base type fails when ...

Mismatched group tags detected in message - protobuf-net

I’m quite new to Silverlight. I’m working for a project which mainly depends on Serialization and Deserialization. Formerly, for WPF I was comfortable with Serializable classes. For silverlight, I ...

Serializing a List of objects using Protobuf-net

I ve been looking to do some binary serialization to file and protobuf-net seems like a well-performing alternative. I m a bit stuck in getting started though. Since I want to decouple the definition ...

DataContract serialization with protobuf-net r275

I just updated to r275 version and it doesn t seem to manage correctly DataContract classes any more By serializing this very simple class: [DataContract] public class ProtoData { [DataMember(...