Skip to content

Instantly share code, notes, and snippets.

@geNAZt
Created September 4, 2013 20:23
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 geNAZt/6442372 to your computer and use it in GitHub Desktop.
Save geNAZt/6442372 to your computer and use it in GitHub Desktop.
public class Main {
public static void main(String [] args) {
System.out.println("Starting test with switch");
Test msg = Test.Test2;
double start = System.currentTimeMillis();
for(Integer i = 0; i < 1000000000; i++) {
switch(msg) {
case Test1:
case Test2:
continue;
default:
break;
}
}
System.out.println("Result of switch perf.: " + (System.currentTimeMillis() - start) + " ms");
System.out.println("Starting test with if");
start = System.currentTimeMillis();
for(Integer i = 0; i < 1000000000; i++) {
if(msg.equals(Test.Test1) || msg.equals(Test.Test2)) {
continue;
}
}
System.out.println("Result of if perf.: " + (System.currentTimeMillis() - start) + " ms");
}
}
public enum Test {
Test1("Test1"),
Test2("Test2"),
Test3("Test3"),
Test4("Test4"),
Test5("Test5");
private final String message;
Test(String message) {
this.message = message;
}
}
@geNAZt
Copy link
Author

geNAZt commented Sep 4, 2013

Starting test with switch
Result of switch perf.: 8298.0 ms
Starting test with if
Result of if perf.: 8460.0 ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment