2017-05-26 50 views
0

我有JSP代碼如下,我可以檢查運行時間的JavaScript代碼,但我無法檢查運行時的servlet進程,runTime始終爲0,我該怎麼辦?如何在IE調試控制檯中顯示servlet運行時間?

<%@ page contentType="text/html; charset=UTF-8"%> 
<%@ page import="java.util.List"%> 
<%@ page import="java.util.ArrayList"%> 
<% 
    long startTime = System.currentTimeMillis(); 
    MyForm myForm = (MyForm) request.getAttribute(ACTION_FORM_KEY); 
    if(myForm == null) { 
     myForm = new PsiSearchForm(); 
    } 

    List<Object> myList = myForm.getMyList(); 
    if(myList == null) { 
     myList = new ArrayList<Object>(); 
    } 
    long endTime = System.currentTimeMillis(); 
    long runTime = endTime - startTime; 
%> 
<html> 
    ... 
</form> 
</body> 
<script language="JavaScript" type="text/JavaScript"> 
    console.time('my_form.jsp'); 
    // javascript process 
    console.timeEnd('my_form.jsp'); 
    console.log("Select My List time: " + <%=runTime%>); 
</script> 
</html> 
+1

你確定這是不爲零,因爲運行時間在1毫秒試試? – Juan

回答

3

使用System.nanoTime();

Oracle

long startTime = System.nanoTime(); 
    // ... the code being measured ... 
    long estimatedTime = System.nanoTime() - startTime; 
相關問題