long now = System.currentTimeMillis();
// Do some non-trivial process here
long timeTaken = System.currentTimeMillis() - now;
And when I say "non-trivial", that's what I mean. Don't waste your time trying to do micro-benchmarks like finding out how long it takes to run "i=i++".