Created
May 25, 2010 04:57
-
-
Save spullara/412778 to your computer and use it in GitHub Desktop.
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 class JavaBenchmark { | |
private String str1, str2, str3, str4; | |
public void run() { | |
System.out.println(String.valueOf(testCompareTo(1000000000))); | |
} | |
private int innerCompareTo() { | |
String str1 = "vm-guld vm-guld vm-guld"; | |
String str2 = "vm-guld vm-guld vm-guldx"; | |
String str3 = "vm-guld vm-guld vm-guldx"; | |
String str4 = "adadaskasdjierudks"; | |
int total = 0; | |
total += str1.compareTo(str2); | |
total += str2.compareTo(str3); | |
total += str3.compareTo(str4); | |
return total; | |
} | |
public double testCompareTo(int loops) { | |
int count = 0; | |
long start = System.currentTimeMillis(); | |
int total = 0; | |
for (int j = 0; j < loops; j++) { | |
count++; | |
for (int i=0; i < 100; i++) { | |
total += innerCompareTo(); | |
} | |
} | |
long elapsed = System.currentTimeMillis() - start; | |
return ((double)count)/elapsed*1000; | |
} | |
public static void main(String[] args) { | |
for (int i = 0; i < 2; i++) { | |
new JavaBenchmark().run(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment