[英]Java long object array assignment time difference
I have a piece of the source code in java8:我有一段java8的源代码:
public class Test {
public static void main(String[] args) {
testObject(1.3);
testObject(1.4);
}
private static void testObject(double num) {
System.out.println("test:" + num);
long sta = System.currentTimeMillis();
int size = 10000000;
Object[] o = new Object[(int) (size * num)];
for (int i = 0; i < size; i++) {
o[i] = "" + i;
}
System.out.println("object[]: " + (System.currentTimeMillis() - sta) + " ms");
}
}
execution Result:执行结果:
test:1.3
object[]: 7694 ms
test:1.4
object[]: 3826 ms
Why is the running time so different when my quantity is 1.4 * size?为什么我的数量是 1.4 * size 运行时间差别这么大?
I wanted to see how Java array assignment works, but I couldn't find anything on google.我想看看 Java 数组赋值是如何工作的,但我在谷歌上找不到任何东西。
In addition you have to keep in mind that System.currentTimeMillis returns a "Wall-Clock-Time".此外,您必须记住 System.currentTimeMillis 返回“Wall-Clock-Time”。 If your OS does a reschedule during the
for
-loop and a different process gets the cpu, the Wall-Clock-Time increases but your program won't execute.如果您的操作系统在
for
了重新安排,并且另一个进程获得了 cpu,则 Wall-Clock-Time 会增加,但您的程序将不会执行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.