Created
September 4, 2013 20:20
-
-
Save geNAZt/6442333 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Main { | |
public static void main(String [] args) { | |
System.out.println("Starting test with switch"); | |
Test msg = Test.Test1; | |
double start = System.currentTimeMillis(); | |
for(Integer i = 0; i < 1000000000; i++) { | |
switch(msg) { | |
case Test1: | |
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)) { | |
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result:
Starting test with switch
Result of switch perf.: 8187.0 ms
Starting test with if
Result of if perf.: 7888.0 ms