class Main
{
{
long start
= System.
nanoTime(); for (int i = 0; i < 1E6; i++) {
methodA((byte) i);
}
System.
out.
println("Method A took: " + (System.
nanoTime() - start
)); for (int i = 0; i < 1E6; i++) {
methodB((byte) i);
}
System.
out.
println("Method B took: " + (System.
nanoTime() - start
)); }
public static String methodA
(byte b
) { // with String methods return String.
format("%8s",
Integer.
toBinaryString(b
& 0xFF
)).
replace(' ',
'0'); }
public static String methodB
(byte b
) { // with bitwise return Integer.
toBinaryString((b
& 0xFF
) + 0x100
).
substring(1); }
}
CmNsYXNzIE1haW4KewogIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluIChTdHJpbmdbXSBhcmdzKSB0aHJvd3MgamF2YS5sYW5nLkV4Y2VwdGlvbgogIHsKICAgICAgbG9uZyBzdGFydCA9IFN5c3RlbS5uYW5vVGltZSgpOwogICAgICBmb3IgKGludCBpID0gMDsgaSA8IDFFNjsgaSsrKSB7CiAgICAgICAgICBtZXRob2RBKChieXRlKSBpKTsKICAgICAgfQogICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIk1ldGhvZCBBIHRvb2s6ICIgKyAoU3lzdGVtLm5hbm9UaW1lKCkgLSBzdGFydCkpOwogICAgICBzdGFydCA9IFN5c3RlbS5uYW5vVGltZSgpOwogICAgICBmb3IgKGludCBpID0gMDsgaSA8IDFFNjsgaSsrKSB7CiAgICAgICAgICBtZXRob2RCKChieXRlKSBpKTsKICAgICAgfQogICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIk1ldGhvZCBCIHRvb2s6ICIgKyAoU3lzdGVtLm5hbm9UaW1lKCkgLSBzdGFydCkpOwogIH0KICAKICBwdWJsaWMgc3RhdGljIFN0cmluZyBtZXRob2RBKGJ5dGUgYikgeyAvLyB3aXRoIFN0cmluZyBtZXRob2RzCiAgICAgIHJldHVybiBTdHJpbmcuZm9ybWF0KCIlOHMiLCBJbnRlZ2VyLnRvQmluYXJ5U3RyaW5nKGIgJiAweEZGKSkucmVwbGFjZSgnICcsICcwJyk7CiAgfQogIAogIHB1YmxpYyBzdGF0aWMgU3RyaW5nIG1ldGhvZEIoYnl0ZSBiKSB7IC8vIHdpdGggYml0d2lzZQogICAgICByZXR1cm4gSW50ZWdlci50b0JpbmFyeVN0cmluZygoYiAmIDB4RkYpICsgMHgxMDApLnN1YnN0cmluZygxKTsKICB9Cn0=