Created
November 19, 2012 10:49
-
-
Save KLIM8D/4110069 to your computer and use it in GitHub Desktop.
SelectionSort benchmark
This file contains 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 characters
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