首页 > 代码库 > stopWatch

stopWatch




1
package com; 2 3 import java.io.FileInputStream; 4 import java.io.InputStream; 5 import java.rmi.Naming; 6 import java.util.List; 7 import java.util.Map; 8 import java.util.Map.Entry; 9 import org.apache.commons.exec.util.MapUtils; 10 import org.apache.poi.ss.usermodel.Cell; 11 import org.apache.poi.ss.usermodel.Sheet; 12 import org.apache.poi.ss.usermodel.Workbook; 13 import org.apache.poi.ss.usermodel.WorkbookFactory; 14 import org.junit.Before; 15 import org.junit.Ignore; 16 import org.junit.Test; 17 import org.springframework.util.StopWatch; 18 19 import com.alibaba.fastjson.JSONObject; 20 import com.gemantic.wealth.application.model.FixProduct; 21 import com.gemantic.wealth.application.model.RecommendFootHc; 22 import com.gemantic.wealth.application.service.FixProductService; 23 import com.gemantic.wealth.application.service.RecommendFootHcService; 24 import com.google.common.collect.Maps; 25 /** 26 * 银杏债老产品维护,请不要删除 27 * @author 作者 PZhang 28 * @date 创建时间:2016-11-28 下午2:05:46 29 * @version 1.0 30 */ 31 //@Ignore 32 public class ReadByMan { 33 public static void main(String[] args){ 34 try { 35 StopWatch sw = new StopWatch("TestWatch"); 36 sw.start("c0"); 37 String key ="702410"; 38 Map<String, String> elementBase = Maps.newHashMap(); 39 elementBase.put("日期基数", "365"); 40 elementBase.put("计息起始日", "1462237200000"); 41 elementBase.put("计息截止日", "1543971600000"); 42 elementBase.put("付息间隔天数", "90,181,272,364,455,546,637,729"); 43 elementBase.put("收益分配方式", "1"); 44 sw.stop(); 45 sw.start("c1"); 46 if(ReadExcel.writeDB(elementBase,key)){ 47 System.out.print(key+"成功!"); 48 }else{ 49 System.out.print(key+"失败!"); 50 } 51 System.out.println(sw.isRunning()); 52 sw.stop(); 53 System.out.println(sw.prettyPrint()); 54 System.out.println(sw.getTaskCount()); 55 System.out.println(sw.getLastTaskName()); 56 System.out.println(sw.isRunning()); 57 System.out.println(sw.shortSummary()); 58 System.out.println(sw.getLastTaskInfo().getTaskName()); 59 System.out.println(sw.getTaskInfo()[0].getTaskName()); 60 } catch (Exception e) { 61 e.printStackTrace(); 62 } 63 } 64 65 }
输出的结果为:##########################
702410成功!true StopWatch TestWatch: running time (millis) = 411 ----------------------------------------- ms % Task name ----------------------------------------- 00011 003% c0 00400 097% c1 2 c1 false StopWatch TestWatch: running time (millis) = 411 c1 c0

总结:

import com.google.common.base.Stopwatch;

import org.apache.commons.lang3.time.StopWatch;

import org.springframework.util.StopWatch;

性能测试用到的时间戳,stopwatch可由3个不同的jar包提供,使用方法不尽相同。简单方便;

以springframework.util.StopWatch效果最好,推荐使用

stopWatch