gpt4 book ai didi

encryption - 代码分析以提高性能 : see CPU cycles inside mscorlib. dll?

转载 作者:行者123 更新时间:2023-12-01 05:24:27 24 4
gpt4 key购买 nike

我做了一个比较 .NET 的小型测试基准测试 System.Security.Cryptography AES 实现与 BouncyCaSTLe.Org 的 AES。

GitHub 代码链接:https://github.com/sidshetye/BouncyBench

我对 AES-GCM 特别感兴趣,因为它是一种“更好的”加密算法,而 .NET 缺少它。我注意到,虽然 .NET 和 BouncyCaSTLe 之间的 AES 实现非常相似,但 GCM 的性能却很差(有关更多信息,请参阅下面的额外背景)。我怀疑这是由于许多缓冲区副本或其他原因。为了更深入地研究,我尝试分析代码(VS2012 => Analyze 菜单栏选项 => Launch performance wizard )并注意到 mscorlib.dll 中有很多 CPU 消耗

enter image description here

问题:在这种情况下,我如何找出消耗大部分 CPU 的资源? 现在我所知道的是“Init() 中的某些行/调用在 mscorlib.ni.dll 中消耗了 47% 的 CPU” - 但不知 Prop 体的行,我不知道在哪里(尝试和)优化。有什么线索吗?

额外背景:

基于 David A. McGrew 的“The Galois/Counter Mode of Operation (GCM)”论文,我读到“二进制字段中的乘法可以使用多种时间-内存权衡。它可以在没有依赖于键的内存的情况下实现,在这种情况下,它的运行速度通常会比 AES 慢几倍。愿意牺牲适量内存的实现可以轻松实现 的速度高于 AES 的速度。”

如果您查看结果,基本的 AES-CBC 引擎性能非常具有可比性。 AES-GCM 添加 GCM 并在 CTR 模式(比 CBC 更快)下重用其下方的 AES 引擎。但是,除了 CTR 模式之外,GCM 还在 GF(2^128) 字段中添加了乘法,因此可能存在其他减速区域。无论如何,这就是我尝试分析代码的原因。

对于感兴趣的人,我的快速测试性能基准在哪里。它位于 Windows 8 VM 和 YMMV 中。该测试是可配置的,但目前它是模拟加密数据库中许多单元格的加密开销(=> 很多但很小的纯文本输入)

Creating initial random bytes ...
Benchmark test is : Encrypt=>Decrypt 10 bytes 100 times

Name time (ms) plain(bytes) encypted(bytes) byte overhead

.NET ciphers
AES128 1.5969 10 32 220 %
AES256 1.4131 10 32 220 %
AES128-HMACSHA256 2.5834 10 64 540 %
AES256-HMACSHA256 2.6029 10 64 540 %

BouncyCastle Ciphers
AES128/CBC 1.3691 10 32 220 %
AES256/CBC 1.5798 10 32 220 %
AES128-GCM 26.5225 10 42 320 %
AES256-GCM 26.3741 10 42 320 %

R - Rerun tests
C - Change size(10) and iterations(100)
Q - Quit

最佳答案

这是微软的一个相当蹩脚的举动,因为他们显然破坏了在 Windows 8 之前运行良好但不再运行的功能,如 this MSDN blog post 中所述。 :
:

On Windows 8 the profiler uses a different underlying technology than what it does on previous versions of Windows, which is why the behavior is different on Windows 8. With the new technology, the profiler needs the symbol file (PDB) to know what function is currently executing inside NGEN’d images.



(……)

It is however on our backlog to implement in the next version of Visual Studio.



该帖子给出了自己生成 PDB 文件的说明(谢谢!)。

关于encryption - 代码分析以提高性能 : see CPU cycles inside mscorlib. dll?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14573972/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com