import java.math.BigInteger;
import java.util.Random;
public class Fuck {
static Runtime run = Runtime.getRuntime();
public static void main(String[] args) {
long start = System.currentTimeMillis();
System.out.println("已用内存" + run.totalMemory());
System.out.println("最大内存" + run.maxMemory());
System.out.println("可用内存" + run.freeMemory());
System.out.println("====================内存浪费中=============");
Random random=new Random();
for(int i=0;i<100000;i++){
int ranInt=random.nextInt(1000);
System.out.println(f(BigInteger.valueOf(ranInt)));
}
long end = System.currentTimeMillis();
System.out.println("执行此程序总共花费了" + ( end - start )+ "毫秒");
System.out.println("已用内存" + run.totalMemory());
System.out.println("最大内存" + run.maxMemory());
System.out.println("可用内存" + run.freeMemory());
run.gc();
System.out.println("清理垃圾后");
System.out.println("已用内存" + run.totalMemory());
System.out.println("最大内存" + run.maxMemory());
System.out.println("可用内存" + run.freeMemory());
}
private static BigInteger f(BigInteger value) {
if(value.compareTo(BigInteger.valueOf(0))==0){
return BigInteger.valueOf(1);
}else{
BigInteger p=value.subtract(BigInteger.valueOf(1));
return f(p).multiply(value);
}
}
}
以时间换空间
最新推荐文章于 2023-05-15 16:14:01 发布