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效果最好,推薦使用