Created
June 17, 2013 08:08
-
-
Save superbob/5795355 to your computer and use it in GitHub Desktop.
Revisions
-
superbob created this gist
Jun 17, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ TimeSpy<Boolean> rsSpy = new TimeSpy<Boolean>() { protected Boolean run() throws Exception { return resultSet.next(); } }; TimeSpy<Boolean> statementSpy = new TimeSpy<Boolean>() { protected Boolean run() throws Exception { return statement.execute(); } }; TimeSpy<Boolean> commitSpy = new TimeSpy<Boolean>() { protected Boolean run() throws Exception { connection.commit(); return true; } }; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ long t1 = rsSpy.getTime()/1000000; long t2 = statementSpy.getTime()/1000000; long t3 = commitSpy.getTime()/1000000; log.info("Ellapsed time : ResultSet.next() : " + t1 + "ms, Statement.execute() : " + t2 + "ms, Connextion.commit() : " + t3 + "ms."); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ rsSpy.doIt() statementSpy.doIt(); commitSpy.doIt(); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ private static abstract class TimeSpy<T> { private long time = 0; protected abstract T run() throws Exception; public T doIt() throws InvocationTargetException { time -= System.nanoTime(); T retVal; try { retVal = run(); } catch (Exception e) { throw new InvocationTargetException(e); } time += System.nanoTime(); return retVal; } public long getTime() { return time; } }