Last active
August 29, 2015 14:08
-
-
Save TrevorS/78afcbad268a0a8bf8f7 to your computer and use it in GitHub Desktop.
"" + c vs. Character.toString(c)
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 TestChar { | |
public static void main(String[] args) { | |
long tests = 1000000000; | |
char c = 'c'; | |
long start = System.nanoTime(); | |
for (int i = 0; i < tests; i++) { | |
String a = "" + c; | |
} | |
System.out.println("Done: " + (System.nanoTime() - start) / 1000000000.0); | |
start = System.nanoTime(); | |
for (int i = 0; i < tests; i++) { | |
String a = Character.toString(c); | |
} | |
System.out.println("Done: " + (System.nanoTime() - start) / 1000000000.0); | |
} | |
} | |
/** | |
* ➜ ~ java TestChar | |
* Done: 3.36814261 | |
* Done: 3.232308615 | |
* ➜ ~ | |
**/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment