Skip to content

Instantly share code, notes, and snippets.

@KLIM8D
Created November 19, 2012 10:49
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 KLIM8D/4110069 to your computer and use it in GitHub Desktop.
Save KLIM8D/4110069 to your computer and use it in GitHub Desktop.
SelectionSort benchmark
public void sortSelection()
{
//Benchmark time start
ThreadMXBean threadmxbean = ManagementFactory.getThreadMXBean();
long startTime;
long finishTime;
startTime = threadmxbean.getCurrentThreadCpuTime();
int arraySize = numbers.length;
while (arraySize > 0)
{
int largest = findLargestElement(arraySize);
swap(largest, arraySize - 1);
arraySize--;
}
finishTime = threadmxbean.getCurrentThreadCpuTime();
System.out.println("Execution time: " + (finishTime-startTime) + " ns" + System.getProperty("line.separator"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment