Oui, et sun.misc.BASE64Decoder est beaucoup plus lent : 9x plus lent que java.xml.bind.DatatypeConverter.parseBase64Binary() et 4x plus lent que org.apache.commons.codec.binary.Base64.decodeBase64(), au moins pour une petite chaîne sur Java 6 OSX.
Voici le programme de test que j'ai utilisé. Avec Java 1.6.0_43 sur OSX :
john:password = am9objpwYXNzd29yZA==
javax.xml took 373: john:password
apache took 612: john:password
sun took 2215: john:password
En fait, c'est avec commons-codec 1.4. Avec la version 1.7, cela semble devenir plus lent :
javax.xml took 377: john:password
apache took 1681: john:password
sun took 2197: john:password
Je n'ai pas testé Java 7 ou d'autres OS.
import javax.xml.bind.DatatypeConverter;
import org.apache.commons.codec.binary.Base64;
import java.io.IOException;
public class TestBase64 {
private static volatile String save = null;
public static void main(String argv[]) {
String teststr = "john:password";
String b64 = DatatypeConverter.printBase64Binary(teststr.getBytes());
System.out.println(teststr + " = " + b64);
try {
final int COUNT = 1000000;
long start;
start = System.currentTimeMillis();
for (int i=0; i<COUNT; ++i) {
save = new String(DatatypeConverter.parseBase64Binary(b64));
}
System.out.println("javax.xml took "+(System.currentTimeMillis()-start)+": "+save);
start = System.currentTimeMillis();
for (int i=0; i<COUNT; ++i) {
save = new String(Base64.decodeBase64(b64));
}
System.out.println("apache took "+(System.currentTimeMillis()-start)+": "+save);
sun.misc.BASE64Decoder dec = new sun.misc.BASE64Decoder();
start = System.currentTimeMillis();
for (int i=0; i<COUNT; ++i) {
save = new String(dec.decodeBuffer(b64));
}
System.out.println("sun took "+(System.currentTimeMillis()-start)+": "+save);
} catch (Exception e) {
System.out.println(e);
}
}
}