假设您最终想要加密字段,无论您的应用程序层是什么,您都必须自己计时才能获得系统和配置的结果。一般来说,您可以使用并行任务进行压缩,如以下示例代码所示:
RijndaelManaged csp = new RijndaelManaged() { Mode = CipherMode.CBC, Padding = PaddingMode.ISO10126 };
// TODO: define Key and IV
Stopwatch encryptionTime = Stopwatch.StartNew();
Parallel.For(0, 1000, i =>
{
string fieldValue = "abcdef...";
byte[] fieldBytes = UTF8Encoding.UTF8.GetBytes(fieldValue);
byte[] fieldEncrypred;
using (var ms = new MemoryStream())
using (var cs = new CryptoStream(ms, csp.CreateEncryptor(), CryptoStreamMode.Write))
{
cs.Write(fieldBytes, 0, fieldBytes.Length);
cs.FlushFinalBlock();
fieldEncrypred = ms.ToArray();
}
});
encryptionTime.Stop();
Console.WriteLine(encryptionTime.Elapsed.TotalMilliseconds);
您可以修改上述内容以满足您的需求并执行您自己的测试。
对于上述示例,您将需要:
using System;
using System.Diagnostics;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;