C# 快速 crc32 计算:
我已经用 Ants 分析了我的应用程序,发现 > 10% 用于 CRC32 计算。 (CRC32 计算是用纯 C# 完成的)
我做了一些谷歌搜索并了解了 Visual Studio 2008 中的以下内在函数:
_mm_crc32_u8
_mm_crc32_u16
_mm_crc32_u32
_mm_crc32_u64
( http://msdn.microsoft.com/en-us/library/bb514036.aspx )
任何人都可以告诉我/告诉我如何使用这些来替换我的自制 CRC32 ?
I've profiled my application with Ants and found out that > 10% is in CRC32 calculations.
(The CRC32-calculation is done in plain C#)
I did some googling and learned about the following intrinsics in Visual Studio 2008 :
_mm_crc32_u8
_mm_crc32_u16
_mm_crc32_u32
_mm_crc32_u64
( http://msdn.microsoft.com/en-us/library/bb514036.aspx )
Can anyone tell me / show me how to use these to replace my homebrew CRC32 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这些年来,CRC32 计算速度越来越快。部分原因是实现优化,还有新的处理器指令可用。因此,这是对近十年之久的问题的新答案!
Stephan Brumme 的 CRC32 页面概述了优化的概述,最后一页日期为 2016 年。Yuri Babich 的 FastCRC 是 Stephan Brumme 和 Stephan Brumme 的快速 C++ CRC32 算法“Slicing-by-16”的 2019 C# 实现。布拉特·齐甘辛。他声称他的版本仅比本机 CLI C++ 快速 CRC32 实现慢一点(大约 10%)。该算法是较旧的 CRC-32-IEEE。
如果您能够选择其他变体,请选择 CRC-32C (Castagnoli)。这在 Crc32C.NET 包中可用。
Crc32.NET 是 Robert Važan 对上述 Crc32C.NET 的 .NET 安全实现,但是对于Crc32算法。
我不知道上述两个 .NET 实现中哪一个对于经典 CRC-32-IEEE 算法来说最快。 性能比较表未引用第一个实现。
Anonymous Coward 的回答指向 crcutil,这是一个小说的高性能 CRC 参考实现多字 CRC 算法由 Andrew Kadatch 和 Bob Jenkins 于 2007 年初发明。新算法针对现代 Intel 和 AMD 处理器进行了大量调整,并且比几乎所有其他软件 CRC 算法快得多。他们 2010 年的论文 下载中列出了我们所知道但又害怕忘记的有关 CRC 的所有内容。本文展示了一些可用于避免重新处理某些数据范围的技巧:
因此,请尽量明智地了解需要计算的内容一旦数据量足够大或者环境有限时。
CRC32 calculations are getting faster over the years. Part because of implementation optimizations but also due to new processor instructions becoming available. Hence this new answer to almost a decade old question!
Stephan Brumme's CRC32 page has an overview of optimizations with the last one dated 2016. FastCRC by Yuri Babich is a 2019 C# implementation of the fast C++ CRC32 algorithm "Slicing-by-16" by Stephan Brumme & Bulat Ziganshin. He claims his version is just a little bit slower (about 10%) than the native CLI C++ fast CRC32 implementation. This algorithm is the older CRC-32-IEEE.
If you have the ability to choose another variant, go for CRC-32C (Castagnoli). This is available in the Crc32C.NET package.
Crc32.NET is a .NET safe implementation of the above Crc32C.NET by Robert Važan but for the the Crc32 algorithm.
I have no idea which of the two .NET implementations above is the fastest for the classic CRC-32-IEEE algorithm. The performance comparison table does not reference the first implementation.
The answer from Anonymous Coward points to crcutil, a high performance CRC reference implementation of a novel Multiword CRC algorithm invented by Andrew Kadatch and Bob Jenkins in early 2007. The new algorithm is heavily tuned towards modern Intel and AMD processors and is substantially faster than almost all other software CRC algorithms. Their 2010 paper Everything we know about CRC but afraid to forget is listed in the downloads. This paper shows some tricks that can be used to avoid reprocessing certain data ranges:
So try to be smart about what needs calculating once the amount of data becomes large enough or when the environment is limited.
围绕此的 AC# 包装器可能是当前大小数据的最佳解决方案。
http://code.google.com/p/crcutil/
Crcutil 库提供了以下功能的高效实现: CRC 算法。它包括 Andrew Kadatch 和 Bob Jenkins 在 2007 年初发明的新型多字 CRC 算法的参考实现。新算法针对现代 Intel 和 AMD 处理器进行了大力调整,并且比几乎所有其他软件 CRC 算法快得多。
硬件辅助 CRC32C:每字节 0.13 (Nehalem) CPU 周期。
64 位及更小的 CRC:每字节 1.0 (Nehalem) - 1.2 (Core) CPU 周期。
128 位 CRC:每字节 1.7 个 CPU 周期。
Haswell 的 AVX2 可能会带来一些可以进一步提高性能的指令,如果是这样的话,如果它们包含在这个库中那就太酷了。
A C# wrapper around this might be the best solution for decent size data currently.
http://code.google.com/p/crcutil/
Crcutil library provides efficient implementation of CRC algorithms. It includes reference implementation of a novel Multiword CRC algorithm invented by Andrew Kadatch and Bob Jenkins in early 2007. The new algorithm is heavily tuned towards modern Intel and AMD processors and is substantially faster than almost all other software CRC algorithms.
Hardware-assisted CRC32C: 0.13 (Nehalem) CPU cycles per byte.
64-bit and smaller CRCs: 1.0 (Nehalem) - 1.2 (Core) CPU cycles per byte.
128-bit CRCs: 1.7 CPU cycles per byte.
Haswell's AVX2 may bring some instructions which may further improve perf, if so, would be cool if they were included in this library.
不确定您是否必须使用这些方法来代替您的自制啤酒。 在此处用 C# 计算 CRC-32 找到了一个很好的实现。
Not sure that you have to use those methods to replace your home brew. Found a good implementation for calculating CRC-32 in C# here.
您可以使用 PInvoke(和纯 c#)或创建 C++/CLI 项目并围绕此函数编写包装器。
你在msdn上看到过例子吗?要计算字符串的 CRC,您只需循环它即可。
嗯,它们是内在函数。这意味着您只有一个选择:创建 C++/CLI 包装器。
You can use PInvoke (and pure c#) or create C++/CLI project and write wrapper around this functions.
Did you saw example on msdn? To compute CRC of string you need just loop through it.
Well, they're Intrinsic functions. It means you have only one option: create C++/CLI wrapper.