protobuf-net 与 protobuf-csharp-port 的性能

发布于 2024-11-02 05:42:02 字数 223 浏览 4 评论 0原文

我知道这两个库的功能和设计,但我还没有发现这两个库之间有任何直接的性能比较。两者绝对都是很棒的库。关于设计,我认为由于反射较少,protobuf-csharp-port 应该稍微快一些,对吗?

另外:

  • protobuf-net V2什么时候发布?有什么计划吗,马克?
  • 乔恩,protobuf-csharp-port 会有新版本吗?

谢谢。

I know the features and design of both libraries but I haven't found any direct performance comparison between those two. Both are definitely great libs. Regarding the design I think protobuf-csharp-port should be slightly faster due to less reflection, right?

Furthermore:

  • When will protobuf-net V2 be released? Any plans, Marc?
  • Will there be a new version of protobuf-csharp-port, Jon?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

相守太难 2024-11-09 05:42:02

重新表现; protobuf-net 旨在尽可能少地执行反射,然后创建高效的数据访问代码。在 v2 中,它在很多方面都更进一步 - 使用更多较低级别的元编程,以及如果你想要(完全可选),预先生成独立序列化器 dll - 因此在运行时反射成本介于最小(如果使用运行时元编程)到零(如果使用预生成)之间。

重新发布; “当它准备好时”;生活是疯狂忙碌的,但是 alpha dll 可用于完整的 .NET 和 iPhone(后者可能适用于大多数较轻的运行时,因为 iPhone 是最受限制的)。最终,现实是(如无赞助等)它会有点落后于工作和家庭等事情——不过,我会尽力找到时间。

我认为更明智的比较是目标; protobuf-net 旨在轻松安装到您现有的 DTO 或域模型中,无需进行大量返工 - 或者用于代码优先场景。它还支持从 .proto 生成,但这不是主要目标(但当然是非常理想的)。它还拥有一个非常不同的 API,围绕常见的 .NET 隐喻,而不是常见的 protobuf 隐喻。

或者换句话说:

  • protobuf-csharp-port 专注于 protobuf,并将 C# / .NET 添加到现有的 protobuf 景观
  • protobuf-net 专注于 C# / .NET,并将 protobuf 添加到现有的 C# / .NET 景观

一个微妙的也许是有区别的——而且事实上,两者都可以为 .NET 提供一个有价值的序列化 API。

作为推论,如果您的主要目标是在同一团队中积极工作的异构环境之间进行互操作,那么 protobuf-csharp-port 可能更适合您。

我对 protobuf 也有点……“松散”,所以我没有(好吧,最小的)内疚,有点超出标准规范(同时保持在协议定义内),以继承,全图,等 - 这在 .NET 生态系统中很常见,但在 protobuf 中没有直接映射。当然,我可以更多地关注 WCF 等工具(以及较小程度的:远程处理)。

Re performance; protobuf-net is designed to perform that reflection as little as possible, creating efficient data access code after that. In v2, it takes this much further in many ways - using much lower-level meta-programming, and if you want it (entirely optional), pre-generation of a standalone serializer dll - so at runtime the reflection cost is somewhere between minimal (if using runtime meta-programming) to nil (if using pre-generation).

Re release; "when it is ready"; life is crazy hectic, but an alpha dll is available for both full .NET and iPhone (this latter will probably work on most of the lighter runtimes, since iPhone is the most restrictive). Ultimately, reality is that (as unsponsored, etc) it is going to lag a bit behind things like work and family - I try to find time when I can, though.

I think a more sensible comparison is the goals; protobuf-net is designed to be easily fitted onto your existing DTO or domain model, without significant rework - or for use in a code-first scenario. It also supports generation from .proto, but that isn't the primary goal (but is of course hugely desirable). It also sports a very different API, geared around common .NET metaphors, rather than common protobuf metaphors.

Or to put it another way:

  • protobuf-csharp-port focuses on protobuf, and adds C# / .NET to the existing protobuf landscape
  • protobuf-net focuses on C# / .NET, and adds protobuf to the existing C# / .NET landscape

A subtle distinction, maybe - and indeed either would make a worthy serialization API for .NET.

As a corollary, if your primary aim is interop between heterogeneous environments that you actively work on in the same team - then maybe protobuf-csharp-port is a better match for you.

I'm also a bit... "loose" with protobuf, so I have no (well, minimal) guilt going a little bit beyond the standard spec (while staying inside the protocol definition) to shoehorn in inheritance, full-graphs, etc - which are common in the .NET ecosystem but have no direct map in protobuf. And of course I can look more at tools like WCF (and to a lesser degree: remoting).

心安伴我暖 2024-11-09 05:42:02

当我使用 protobuf-csharp-port 时,我发现这个库中有一个错误。
例如,当我创建如下消息:

    message CalculateInfo{
    required string CalStarttime=1;
    optional string CalEndtime=2;
    required string Smiles=3;
    optional string CAS=4;
    optional string ChName=5;
    optional string EnName=6;
    required string Param=7;
    required bytes Result=8;
    required bool IsFinished=9;
}

    message GetAllCalulateResponse{
        required bool  isSuccessful = 1;
        required int32 Count=2;
        repeated CalculateInfo History=3;

    }

code like this(in python):

msg_resp.Count = len(resultSets)

calculateInfo = [None] * msg_resp.Count
cnt = 0
for result in resultSets:
    calculateInfo[cnt] = msg_resp.History.add()
    calculateInfo[cnt].CalStarttime = str(result.calculateStartTime)
    calculateInfo[cnt].CalEndtime = result.calculateEndTime.strftime('%Y-%m-%d %X')
    calculateInfo[cnt].IsFinished = result.isFinished
    calculateInfo[cnt].Param = result.paramInfo
    calculateInfo[cnt].Result = str('ff'*1000) #result.result

    calculateInfo[cnt].Smiles = result.smilesInfo.smilesInfo
    calculateInfo[cnt].CAS = result.smilesInfo.casInfo

    nameSets = CompoundName.objects.filter(simlesInfo=result.smilesInfo.pk,isDefault=True)
    for nameSet in nameSets:
        if nameSet.languageID.languageStr == Chinese_Name_Label:
            calculateInfo[cnt].ChName = nameSet.nameStr 
        elif nameSet.languageID.languageStr == English_Name_Label:
            calculateInfo[cnt].EnName = nameSet.nameStr

    cnt = cnt +1 

C# 代码将出现此错误:
解析协议消息时,输入意外地在字段中间结束。这可能意味着输入已被截断,或者嵌入的消息误报了自己的长度。

当我缩小calculateInfo[cnt].Result时,它会再次起作用。

When I use protobuf-csharp-port, I found a bug in this lib.
For example, when I create message like this:

    message CalculateInfo{
    required string CalStarttime=1;
    optional string CalEndtime=2;
    required string Smiles=3;
    optional string CAS=4;
    optional string ChName=5;
    optional string EnName=6;
    required string Param=7;
    required bytes Result=8;
    required bool IsFinished=9;
}

    message GetAllCalulateResponse{
        required bool  isSuccessful = 1;
        required int32 Count=2;
        repeated CalculateInfo History=3;

    }

code like this(in python):

msg_resp.Count = len(resultSets)

calculateInfo = [None] * msg_resp.Count
cnt = 0
for result in resultSets:
    calculateInfo[cnt] = msg_resp.History.add()
    calculateInfo[cnt].CalStarttime = str(result.calculateStartTime)
    calculateInfo[cnt].CalEndtime = result.calculateEndTime.strftime('%Y-%m-%d %X')
    calculateInfo[cnt].IsFinished = result.isFinished
    calculateInfo[cnt].Param = result.paramInfo
    calculateInfo[cnt].Result = str('ff'*1000) #result.result

    calculateInfo[cnt].Smiles = result.smilesInfo.smilesInfo
    calculateInfo[cnt].CAS = result.smilesInfo.casInfo

    nameSets = CompoundName.objects.filter(simlesInfo=result.smilesInfo.pk,isDefault=True)
    for nameSet in nameSets:
        if nameSet.languageID.languageStr == Chinese_Name_Label:
            calculateInfo[cnt].ChName = nameSet.nameStr 
        elif nameSet.languageID.languageStr == English_Name_Label:
            calculateInfo[cnt].EnName = nameSet.nameStr

    cnt = cnt +1 

C# code will occur this error:
While parsing a protocol message, the input ended unexpectedly in the middle of a field. This could mean either than the input has been truncated or that an embedded message misreported its own length.

when I small calculateInfo[cnt].Result, it works again.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文