我正在尝试评估程序的执行时间,但是却得到了错误的答案。完成> 20s的操作将注册为3s
这是我的代码:
Public Function Encrypt(ByVal strValue As String) As String
'Create instance of a Rijndael Managed object
Dim aes As New RijndaelManaged
'Set appropriate values of object
aes.Padding = PaddingMode.PKCS7
aes.KeySize = 256
aes.Mode = CipherMode.CBC
'Create streams to work with encryption process
Dim msEncrypt As New MemoryStream()
'SharedKey = "64 byte string"
'IV = "32 byte string"
Dim SharedKey As Byte() = Encoding.GetEncoding(1252).GetBytes(strSharedKey)
Dim IV As Byte() = Encoding.GetEncoding(1252).GetBytes(strIV)
Dim csEncrypt As New CryptoStream(msEncrypt, aes.CreateEncryptor(SharedKey, IV), CryptoStreamMode.Write)
'Convert string value to byte array
Dim toEncrypt As Byte() = Encoding.GetEncoding(1252).GetBytes(strValue)
toEncrypt = Encoding.Convert(Encoding.GetEncoding(1252), Encoding.UTF8, toEncrypt)
'Perform encryption
csEncrypt.Write(toEncrypt, 0, toEncrypt.Length)
csEncrypt.FlushFinalBlock()
'Return Base64 string
Return Convert.ToBase64String(msEncrypt.ToArray())
'Dim u As System.Text.UnicodeEncoding = System.Text.Encoding.Unicode
'Dim a As System.Text.ASCIIEncoding = System.Text.Encoding.ASCII
'Return a.GetByteCount(SharedKey) '64 bytes
End Function
我在start_time的初始声明周围加上了星号。抱歉,所有代码都转储了,但是我真的不知道time()有什么问题。