Here you can find the source of printExecutionTime(long startTime, long endTime, String className, String methodName)
Parameter | Description |
---|---|
startTime | Long representing the current System time when the method started. |
endTime | Long representing the current System time when the method finished. |
className | The name of the class the method belongs to. |
methodName | A String containing the name of the current running method. |
public static void printExecutionTime(long startTime, long endTime, String className, String methodName)
//package com.java2s; /*//w w w . ja va 2s . c o m * Copyright (C) 2016 lefte * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; public class Main { /** * Prints the execution time of a current running method in seconds. * @param startTime Long representing the current System time when the method started. * @param endTime Long representing the current System time when the method finished. * @param className The name of the class the method belongs to. * @param methodName A String containing the name of the current running method. */ public static void printExecutionTime(long startTime, long endTime, String className, String methodName) { DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Calendar cal = Calendar.getInstance(); long runningTime = (endTime - startTime) / 1000; //Convert to seconds System.err.println("INFO: " + dateFormat.format(cal.getTime()) + " " + className + " " + methodName + " run for " + (runningTime == 1 ? runningTime + " second." : runningTime + " seconds.")); } }