如何保持iOS应用程序的运行时间一致?

时间:2019-05-21 02:54:31

标签: ios swift iphone xcode

我已经开发了一个简单的iOS应用程序,可以对随机生成的消息进行加密和解密。在iPhone 8上部署应用程序时,运行时间有时会有所不同。在大多数情况下,它是一致的。我试图了解为什么有时运行时间会有所不同。我确保在运行时没有其他应用程序打开,以确保没有其他应用程序在使用iPhone的处理器。

这些是我的操作按钮,它们调用加密和解密功能,这就是我测量经过时间的方式:

@IBAction func enc(_ sender: Any) {
    let info = ProcessInfo.processInfo
    let begin = info.systemUptime

    enc0.text = "Enc-c0: \(e0)"
    enc1.text = "Enc-c1: \(e1)"

    let time = (info.systemUptime - begin)

    time1.text = "Enc Time: \(time)"
}

@IBAction func dec(_ sender: Any) {
    let info = ProcessInfo.processInfo
    let begin = info.systemUptime

    let decryption = dDec(encryption0:e0,encryption1:e1)

    dec.text = "Dec: \(decryption)"

    let time = (info.systemUptime - begin)

    time2.text = "Dec Time: \(time)"
}

这是被调用的两个函数:

func dEnc() -> (BigUInt,BigUInt){

    let r:BigUInt = BigUInt.randomInteger(lessThan: (p-2))

    let c0:BigUInt = x.power(_:r,modulus:p)

    let a:BigUInt = m.power(_:1, modulus: p)
    let b:BigUInt = (pub_m.multiplied(by: pub_r)).power(_:r, modulus: p)
    let c1:BigUInt = a.multiplied(by: b).power(1, modulus: p)

    return (c0, c1)
}


func dDec(encryption0:BigUInt, encryption1:BigUInt) -> BigUInt{

    let a = encryption1
    var b = encryption0.power(priv_m, modulus: p)
    var c = encryption0.power(priv_r, modulus: p)

    b = b.inverse(p)!
    c = c.inverse(p)!

    let d = ((a.multiplied(by: b)).multiplied(by: c)).power(1, modulus: p)
    return (d)
}

应用程序运行正常,但运行时有时会有所不同。我需要处理什么以确保运行时一致吗?

0 个答案:

没有答案