62,614
社区成员
发帖
与我相关
我的任务
分享
package test;
public class Demo {
public static void main(String[] args) {
int a = 100;
int b = 16;
doSomething(a, b);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
}
doSomething2(a, b);
}
public static void doSomething(int a, int b){
long startTime = System.currentTimeMillis();
for(int i=0; i<2147483647; i++){
int c = a+b;
}
long endTime = System.currentTimeMillis();
System.out.println("a+b用时:"+(endTime - startTime));
}
public static void doSomething2(int a, int b){
long startTime = System.currentTimeMillis();
for(int i=0; i<2147483647; i++){
int c=a*b;
}
long endTime = System.currentTimeMillis();
System.out.println("a*b用时:"+(endTime - startTime));
}
}