我正在测试使用webcryptoapi在Typescript中编写的基于位置的加密库的时间性能。我想了解MacOs和android等不同平台的时差。为此,我使用了Macbook pro(2017)和Samsung galaxy s2 android平板电脑。
为了测试该库,我创建了一个简单的HTML页面,其中包含一些文本框区域,加密按钮和解密按钮。单击按钮时,将进行加密。现在从 performance.now()函数可以看到下面的内容,我计算时差并将其记录到控制台上。但是,我意识到与Macbook Pro计算机相比,平板电脑上的加密时间总是更短。从逻辑上讲,笔记本电脑不是比平板电脑更坚固吗?还是与API调用速度有关?尽管平板电脑功能较弱,但我始终不知道平板为何总是更快。预先感谢。
public async encrypt(transformedLocation: Int32Array, message: String, toleranceDistance: number) {
let context = this
try {
let keyDerivationStartTime = performance.now();
let key = await this.deriveKey(transformedLocation)
let keyDerivationFinishTime = performance.now();
let keyhash = await this.calculateKeyHash(key)
let plaintTextBytes = DataConvertionCalculations.stringToByteArray(message)
let encryptionStartTime = performance.now();
let encryptedMessage = await this.encryptMessage(key, plaintTextBytes)
let encryptionFinishTime = performance.now();
let result = new ResultHolder(encryptedMessage, keyhash, toleranceDistance, context.salt, context.ivBytes)
let wholeTime= performance.now();
console.log("Key derivation time:" + (keyDerivationFinishTime-keyDerivationStartTime))
console.log("Encryption operation time:" + (encryptionFinishTime-encryptionStartTime))
console.log("Whole encryption operation took:" + (wholeTime-keyDerivationStartTime))
return result
} catch (err) {
return err
}
}