Last active
August 29, 2015 14:08
-
-
Save TrevorS/f34107f4261458666d4a to your computer and use it in GitHub Desktop.
"" + (char) b vs. Character.toString((char) b)
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; | |
byte b = (byte) 'b'; | |
long start = System.nanoTime(); | |
for (int i = 0; i < tests; i++) { | |
String a = "" + (char) b; | |
} | |
System.out.println("Done: " + (System.nanoTime() - start) / 1000000000.0); | |
start = System.nanoTime(); | |
for (int i = 0; i < tests; i++) { | |
String a = Character.toString((char) b); | |
} | |
System.out.println("Done: " + (System.nanoTime() - start) / 1000000000.0); | |
} | |
} | |
/** | |
* Done: 3.401561704 | |
* Done: 3.238949012 | |
**/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment