DecimalFormat和BigDecimal对格式化的性能对比

	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		for (int i = 0; i < 1000000; i++) {
			double avgDeleteDelay = Double.valueOf(DECIMAL_FRORMAT
					.format((double) RandomUtils.nextInt()
							/ RandomUtils.nextInt()));
		}
		System.out.println(System.currentTimeMillis() - start);

		start = System.currentTimeMillis();
		for (int i = 0; i < 1000000; i++) {

			double avgDeleteDelay = BigDecimal
					.valueOf(RandomUtils.nextInt())
					.divide(BigDecimal.valueOf(RandomUtils.nextInt()), 2,
							RoundingMode.HALF_UP).doubleValue();
		}
		System.out.println(System.currentTimeMillis() - start);
	}


 输出

2840
538


 

你可能感兴趣的:(String,UP)