SimpleDateFormat三种不同的应用办法
这里总结一下SimpleDateFormat的三种用法不同的性能比照后果。
尽管SimpleDateFormat性能最差,线程不平安,然而一些老旧的零碎还是有那么多的人用,这里就简略比照一下性能差别
代码
public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.S"); @ApiOperation("SimpleDateFormat-获取以后工夫戳") @ApiResponses({ @ApiResponse(code = 200, message = "OK", response= R.class), }) @RequestMapping(value = "/SimpleDateFormat", method = RequestMethod.GET) public String SimpleDateFormatCase(){ long startTime = System.currentTimeMillis(); SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.S"); String date = sdf1.format(System.currentTimeMillis()); log.info("解析工夫耗时:" + (System.currentTimeMillis() - startTime) + "ms"); return date; } @ApiOperation("SimpleDateFormat-获取以后工夫戳2-复用SimpleDateFormat") @ApiResponses({ @ApiResponse(code = 200, message = "OK", response= R.class), }) @RequestMapping(value = "/SimpleDateFormat2", method = RequestMethod.GET) public String SimpleDateFormatCase2(){ long startTime = System.currentTimeMillis(); String date = sdf.format(System.currentTimeMillis()); log.info("解析工夫耗时:" + (System.currentTimeMillis() - startTime) + "ms"); return date; } @ApiOperation("SimpleDateFormat-获取以后工夫戳3-应用线程锁") @ApiResponses({ @ApiResponse(code = 200, message = "OK", response= R.class), }) @RequestMapping(value = "/SimpleDateFormat3", method = RequestMethod.GET) public String SimpleDateFormatCase3(){ String date = DateFormatUtil.formatDateTime(new Date()); return date; }
压测形式
间接用jmeter发压,10并发,发压100s,服务器监控用sar命令简略监控(也不是什么很简单的业务,第三方监控组件没必要)
模型1后果
TPS:111.3笔/s,RT:88ms,CPU:37.1%
模型2后果
TPS:115笔/s,RT:86ms,CPU:20.25%
模型3后果
TPS:116笔/s,RT:85ms,CPU:12.92%
后果统计
模型 | TPS | 响应工夫 | 90%Line | 95%Line | 99%Line | 资源耗费 |
---|---|---|---|---|---|---|
1 | 111.3 | 88 | 121 | 149 | 210 | 37.01% |
2 | 115 | 86 | 115 | 139 | 204 | 20.25% |
3 | 116 | 85 | 110 | 125 | 203 | 12.92% |
能够不言而喻的看到TPS和RT其实相差不多的,次要还是利用资源耗费相差较大。