Skip to content

Instantly share code, notes, and snippets.

@cmlewis
Created October 30, 2014 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmlewis/ab120fbab166257816b1 to your computer and use it in GitHub Desktop.
Save cmlewis/ab120fbab166257816b1 to your computer and use it in GitHub Desktop.
Create a 'timer' in Java to measure the duration of some code in milliseconds and minutes.
// Get the current system time to calculate duration
long startTime = System.currentTimeMillis();
// Do logic here
// Get the end time and calculate duration
long endTime = System.currentTimeMillis();
long durationInMs = endTime - startTime;
long durationInMins = durationInMs/60000;
logger.debug("This script took " + durationInMs + " ms or " + durationInMins + " minutes to run.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment