You can do something simple:
long begin = System.currentTimeMillis();
doWork();
long end = System.currentTimeMillis();
long dt = end - begin;
A more mature way (especially if you need to do this many times in many places), use the library. Take a look at perf4j . You can put the annotation @Profiledon the methods, and it will automatically generate some statistics and write them to the log file.
Roman source
share