001/** 002 * Copyright (C) 2007 - 2016, Jens Lehmann 003 * 004 * This file is part of DL-Learner. 005 * 006 * DL-Learner is free software; you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation; either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * DL-Learner is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package org.dllearner.utilities.statistics; 020 021/** 022 * Copyright (C) 2007-2008, Jens Lehmann 023 * 024 * This file is part of DL-Learner. 025 * 026 * DL-Learner is free software; you can redistribute it and/or modify 027 * it under the terms of the GNU General Public License as published by 028 * the Free Software Foundation; either version 3 of the License, or 029 * (at your option) any later version. 030 * 031 * DL-Learner is distributed in the hope that it will be useful, 032 * but WITHOUT ANY WARRANTY; without even the implied warranty of 033 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 034 * GNU General Public License for more details. 035 * 036 * You should have received a copy of the GNU General Public License 037 * along with this program. If not, see <http://www.gnu.org/licenses/>. 038 * 039 */ 040import org.apache.log4j.Logger; 041 042/** 043 * Class for counting time and outputting it. 044 * 045 * @author Unknown 046 */ 047public class SimpleClock { 048 049 private static Logger logger = Logger.getLogger(SimpleClock.class); 050 051 private long time; 052 053 public SimpleClock() { 054 time = System.currentTimeMillis(); 055 } 056 057 /** 058 * prints time needed and resets the clock 059 */ 060 public void printAndSet() { 061 logger.info("needed " + getTime() + " ms"); 062 setTime(); 063 } 064 065 /** 066 * prints time needed and resets the clock 067 * 068 * @param s 069 * String for printing 070 */ 071 public void printAndSet(String s) { 072 logger.info(s + " needed " + getTime() + " ms"); 073 setTime(); 074 } 075 076 public String getAndSet(String s) { 077 String ret = s + " needed " + getTime() + " ms"; 078 setTime(); 079 return ret; 080 } 081 082 /** 083 * prints time needed 084 * 085 * @param s 086 * String for printing 087 */ 088 public void print(String s) { 089 logger.info(s + " needed " + getTime() + " ms"); 090 } 091 092 /** 093 * resets the clock 094 */ 095 public void setTime() { 096 time = System.currentTimeMillis(); 097 } 098 099 /** 100 * resets the clock 101 */ 102 public void reset() { 103 setTime(); 104 } 105 106 /** 107 * @return the needed time up to now in ms 108 */ 109 public long getTime() { 110 long now = System.currentTimeMillis(); 111 return now - time; 112 } 113 114}