我有一个非常奇怪的现象发生。我正在散列一些模拟ssoid,并对其进行计时,因为我们的应用程序对计时至关重要。函数的第一次运行大约需要210毫秒,这太荒谬了,根本不起作用。但是,第二、第三和第四次运行每次需要几千纳秒。我真的很困惑,怎么了?我能做些什么让第一次跑得同样快吗?
请参见此处的代码:
object Main {
def main(args: Array[String]): Unit = {
val qq = "847bf1dc46ca22dc93259c5e857d6333"
val oo = "847bf1dc46ca22dc9eriuerie9duy45"
val xx = "909909ewufv9026854509erie9ifkf3"
val ww = "65984jg3oiqh4g3q383423932824344"
val qqq = getBytes(qq)
val ooo = getBytes(oo)
val xxx = getBytes(xx)
val www = getBytes(ww)
val t1 = System.nanoTime
val r1 = XxHash64.hashByteArray(qqq, seed = 0)
val duration = (System.nanoTime - t1)
val t2 = System.nanoTime
val r2 = XxHash64.hashByteArray(ooo, seed = 0)
val duration2 = (System.nanoTime - t2)
val t3 = System.nanoTime
val r3 = XxHash64.hashByteArray(xxx, seed = 0)
val duration3 = (System.nanoTime - t3)
val t4 = System.nanoTime
val r4 = XxHash64.hashByteArray(www, seed = 0)
val duration4 = (System.nanoTime - t4)
println(duration)
println(duration2)
println(duration3)
println(duration4)
println(r1)
println(r2)
println(r3)
println(r4)
}
(还要注意的是,我认识到这是一种不切实际的计时方式,但我才刚刚开始。)
暂无答案!
目前还没有任何答案,快来回答吧!